Credits: This tutorial is written by David Andersson (Liorean). Please see footnote for more information on author.
simplest way to simulate this functionality is via object literals. Let me
illustrate with a custom
parseInt() function that can accept its
two arguments in any order:
The key to the above is passing in an object literal as the function's sole parameter instead of separate, "authentic" parameter(s). Now, this is a pretty useless example, but it illustrates my point of creating a function that can accept arguments in any order and via a more intuitive name:value format. Such functions are much more robust than standard ones, not to mention user friendly in cases where the function takes on a lot of parameters.
- Tutorial introduction
- Detecting the existence of a parameter