Skip to content

Instantly share code, notes, and snippets.

@drunkcod
Created April 10, 2012 12:32
Show Gist options
  • 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;
}
@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