HPCloud-JS

API Docs for: 1.0.0
Show:

Futil Class

Defined in: lib/futil.js:25
Module: hpcloud

Function Utilities

Item Index

Methods

Methods

argsWithFn

(
  • arguments
  • names
)
Object static

Defined in lib/futil.js:34

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 Object

    An arguments object for a function.

  • names Array

    The 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 (){}