Skip to content

Instantly share code, notes, and snippets.

Created April 21, 2011 11:16
What would you like to do?
function fakeLength(fn, length) {
if (length == fn.length) return fn;
var fakeArgs = [];
while(length--) fakeArgs.push('$fakeArg'+length);
return eval('(function('+fakeArgs.join(',')+'){ return fn.apply(this, arguments); })');
Function.prototype.allRequired = function(){
var fn = this,
wrapped = function(){
if (arguments.length >= fn.length)
return fn.apply(this, arguments);
throw new Error('Oh Shit...');
return fakeLength(wrapped, fn.length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment