Futil Class
Function Utilities
Item Index
Methods
- argsWithFn static
Methods
argsWithFn
(
Object
static
-
arguments
-
names
Re-scan an argument list with internal optional arguments and a trailing function.
It is often considered best to have callback functions listed as the last argument on a function call. This provides a way of re-setting arguments so that optional arguments are set to 'undefined' and the function callback is moved to the far right of the arguments list.
Usage:
Parameters:
-
arguments
ObjectAn arguments object for a function.
-
names
ArrayThe names of all possible arguments associated with the arguments object.
Returns:
Object:
A new object of arguments.
Example:
function example(a, b, c, callback) {
var args = Futil.argsWithFn(arguments, ['a', 'b', 'c', 'callback']);
console.log("a: %s, b: %s, c: %s, callback: %s", args.a, args.b, args.c, args.callback);
}
// Call like this...
example(1, function(){});
// Output:
// a: 1, b: undefined, c: undefined, callback: function (){}