practical variable argument handling in node.js
Switch branches/tags
Nothing to show
Pull request Compare This branch is 1 commit behind cloudhead:master.
Latest commit 246ff1e Apr 8, 2010
Failed to load latest commit information.
LICENSE license Apr 8, 2010 updated README with example Apr 8, 2010
index.js init Apr 8, 2010


variable argument handling for functions taking a callback


JavaScript has very poor argument handling. vargs tries to make it simpler.


var Args = new("vargs").Constructor;

function (/* [arg1, arg2, ...][,callback] */) {
    var args = new(Args)(arguments);
    args.first;    // first argument
    args.last;     // last argument before callback
    args.callback; // callback argument, or an empty function
    args.all;      // all arguments except callback
    args.length;   // number of arguments, not including callback
    args.callbackGiven(); // returns true or false;          // last argument, including callback
    args.array;           // all arguments, including callback


For a real-world example of vargs, check