2 * args.js: function argument parsing helper utility
4 * (C) 2012, Nodejitsu Inc.
9 var utile = require('./index');
12 // ### function args(_args)
13 // #### _args {Arguments} Original function arguments
15 // Top-level method will accept a javascript "arguments" object (the actual keyword
16 // "arguments" inside any scope), and attempt to return back an intelligent object
17 // representing the functions arguments
19 module.exports = function (_args) {
20 var args = utile.rargs(_args),
24 // Find and define the first argument
26 Object.defineProperty(args, 'first', { value: args[0] });
29 // Find and define any callback
31 _cb = args[args.length - 1] || args[args.length];
32 if (typeof _cb === "function") {
33 Object.defineProperty(args, 'callback', { value: _cb });
34 Object.defineProperty(args, 'cb', { value: _cb });
39 // Find and define the last argument
42 Object.defineProperty(args, 'last', { value: args[args.length - 1] });