passing optional arguments in JavaScript

Posted . Visible to the public.

You can call a JavaScript object while passing an array of arguments with the method apply.

given:

function method(arg1, arg2){
  console.log([arg1, arg2]);
}

you can use:

method.apply(this, ['one', 'two']);
Jonathan Knapp
Posted by Jonathan Knapp to Knowledge is Power! (2012-03-23 22:13)