Created
December 5, 2013 21:09
-
-
Save STRd6/7813942 to your computer and use it in GitHub Desktop.
Rename function in JS
This file contains 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
var f, rename, renamedFunction; | |
rename = function(fn, name) { | |
return Function("fn", "return (function " + name + "(){\n return fn.apply(this, arguments)\n});")(fn); | |
}; | |
f = function() {}; | |
renamedFunction = rename(f, "a_new_name"); | |
alert(renamedFunction.name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
All i know is I've used that method with success, and seen it used elsewhere. I haven't tried it in every browser, so mileage may vary.