Multiple arguments vs. options object

When creating a JavaScript function with multiple arguments, I am always confronted with this choice: pass a list of arguments vs. pass an options object. For example I am writing a function to map a nodeList to an array: function map(nodeList, callback, thisObject, fromIndex, toIndex){ … } I could instead use this: function map(options){ … … Read more

Why can I use a function before it’s defined in JavaScript?

This code always works, even in different browsers: function fooCheck() { alert(internalFoo()); // We are using internalFoo() here… return internalFoo(); // And here, even though it has not been defined… function internalFoo() { return true; } //…until here! } fooCheck(); I could not find a single reference to why it should work, though. I first … Read more

Arguments or parameters? [duplicate]

This question already has answers here: What’s the difference between an argument and a parameter? (36 answers) Closed 9 years ago. I often find myself confused with how the terms ‘arguments’ and ‘parameters’ are used. They seem to be used interchangeably in the programming world. What’s the correct convention for their use? 12 Answers 12

How to use R’s ellipsis feature when writing your own function?

The R language has a nifty feature for defining functions that can take a variable number of arguments. For example, the function data.frame takes any number of arguments, and each argument becomes the data for a column in the resulting data table. Example usage: > data.frame(letters=c(“a”, “b”, “c”), numbers=c(1,2,3), notes=c(“do”, “re”, “mi”)) letters numbers notes … Read more

Passing a string with spaces as a function argument in Bash

I’m writing a Bash script where I need to pass a string containing spaces to a function in my Bash script. For example: #!/bin/bash myFunction { echo $1 echo $2 echo $3 } myFunction “firstString” “second string with spaces” “thirdString” When run, the output I’d expect is: firstString second string with spaces thirdString However, what’s … Read more