Skip to content Skip to sidebar Skip to footer

How To Create A Variadic (with Variable Length Argument List) Function Wrapper In Javascript

The intention is to build a wrapper to provide a consistent method of calling native functions with variable arity on various script hosts - so that the script could be executed in

Solution 1:

Just use apply(). And for your antiquated execution engines, just do this

if ( 'undefined' == typeofFunction.prototype.apply )
{
  Function.prototype.apply = function( context, args )
  {
    // whatever hacky way you want to implement it - i guess eval.
  }
}

Solution 2:

Just like the automatic 'this' variable, there is an 'arguments' variable that holds all the arguments passed in to the function. See javascript variadic.

Post a Comment for "How To Create A Variadic (with Variable Length Argument List) Function Wrapper In Javascript"