Skip to content

Instantly share code, notes, and snippets.

@drunkcod
Created April 10, 2012 12:32
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 drunkcod/2351063 to your computer and use it in GitHub Desktop.
Save drunkcod/2351063 to your computer and use it in GitHub Desktop.
Dynamically add 'require' to any function
function addRequire(target) {
while(target.next){ target = target.next; }
function requireArguments() {
var args = requireArguments.args;
for(var i = 0; i != args.length; ++i) {
require(arguments[i], args[i]);
}
return requireArguments.next.apply(this, arguments);
}
requireArguments.args = /\((.*?)\)/.exec(target.toString())[1].replace(' ','').split(',');
requireArguments.next = target;
return requireArguments;
}
@kitofr
Copy link

kitofr commented Apr 10, 2012

Good stuff... thanks :)

@drunkcod
Copy link
Author

improved the naming & proper handling of return values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment