Ok, so this is nothing new nor is it something that hasn't been blogged about before.  However, I thought I'd share in case it helps some other googler that can't find what they're looking for 🙂

So in JavaScript, most functions have a pretty standard form: you name the function and then define which arguments you wish to pass to the function.  Depending on how you work out the logic in the remainder of the function, the arguments can all be required, all be optional, or whatever.

The one major drawback, however, is that the arguments must be passed in the proper order.  For example, if I have a describeMovie() function that takes an actor, title, and year argument, the order I define these arguments in will be the order in which I have to pass them in my function call.

function describeMovie(actor,title,year) {    // alert the movie’s lead actor    alert(actor);    …………}

would require

onclick="describeMovie('Bruce Willis','Surrogates','2009')"

in order to work properly. 

(This won’t work:)

onclick="describeMovie('Bruce Willis','2009','Surrogates')"

Also, while I can easily pass the actor and title parameters without the year parameter (describeMovie('Bruce Willis','Surrogates')), I’ll run into issues if I try to pass just the actor and year parameters (describeMovie('Bruce Willis','2009')), for the order in which they are More >