Skip to content

Instantly share code, notes, and snippets.

@rwz
Created April 21, 2011 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwz/934203 to your computer and use it in GitHub Desktop.
Save rwz/934203 to your computer and use it in GitHub Desktop.
!function(){
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);
else
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