Skip to content
practical variable argument handling in node.js
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib fixed README. moved index.js to lib/vargs.js
LICENSE license fixed README. moved index.js to lib/vargs.js


variable argument handling for functions taking a callback


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


var Args = require("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

Something went wrong with that request. Please try again.