Created
June 17, 2014 16:30
-
-
Save kamikat/b050680d9f7b2fe2bbbe to your computer and use it in GitHub Desktop.
Backward function argument parsing style...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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