30 Oct 2008

Function Argument Passing

Javascript's function argument passing is nice. Every function has an implicit variable named arguments that holds all the arguments, and the function declaration is only a shorthand. To look at it differently, with varargs and optional parameters, a function in effect takes a single argument which is a hashtable (or list, if keyword arguments are not supported). If every function takes the same single argument, why make the programmer declare it? Define an implicit variable named arguments. Then what do you put in the space traditionally used for function arguments? That can become a shortcut, so that you can access an argument by its name rather than as arguments.name.

No comments:

Post a Comment