Passing Hashes (Objects) as Arguments to Functions
If you don’t know this already, JavaScript functions which accept a single object (hash) which contains each of the properties are far better than functions which accept a number of individual parameters. The reason is that using a hash no longer requires your function’s API to depend on the presence of certain arguments or on their order, and it also means that updating the functions to support new arguments will have no negative impact on all other uses (and users) of it.
So, instead of functions like:
function concat(str1, str2){
return str1 + str2;
}
concat("This API", " is bad.");
You should create functions that work like this:
function concat(props){
return props.str1 + props.str2;
}
concat({str1:"This API", str2:" is better.});




Subchild is a blog about web development. It's author is Aleksandar Kolundzija, himself a web developer
for 10++ years, presently a Hacker-in-Residence at betaworks. Prior to betaworks, Alex worked at Google, Meebo,
MLB Advanced Media (MLB.com), Razorfish, and elsewhere.