Skip to content

Instantly share code, notes, and snippets.

@kamikat
Created June 17, 2014 16:30
Show Gist options
  • Save kamikat/b050680d9f7b2fe2bbbe to your computer and use it in GitHub Desktop.
Save kamikat/b050680d9f7b2fe2bbbe to your computer and use it in GitHub Desktop.
Backward function argument parsing style...
module.exports = function (capture, handler, forceAll) {
var args = Array.prototype.slice.call(arguments, 0);
forceAll = args.pop();
if (typeof(forceAll) != 'boolean') {
handler = forceAll;
forceAll = true;
} else {
handler = args.pop();
}
if (typeof(handler) != 'function') {
capture = handler;
handler = null;
} else {
capture = args.pop();
}
if (!Array.isArray(capture)) {
if (capture) {
args.push(capture);
capture = args.slice(0);
} else {
capture = null;
}
}
return {
capture: capture,
handler: handler,
forceAll: forceAll
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment