Created
April 10, 2012 12:32
-
-
Save drunkcod/2351063 to your computer and use it in GitHub Desktop.
Dynamically add 'require' to any function
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
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; | |
} |
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
Good stuff... thanks :)