Skip to content

Instantly share code, notes, and snippets.

@carlosascari
Last active February 19, 2016 06:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosascari/78c9eb997a1583df93d3 to your computer and use it in GitHub Desktop.
Save carlosascari/78c9eb997a1583df93d3 to your computer and use it in GitHub Desktop.
A Hacky way of renaming an existing function
/**
* Renames and existing function.
*
* @private
* @method rename_function
* @param name {String}
* @param fn {Function}
* @return Function
*/
function rename_function(name, fn)
{
return (
new Function(
"return function (call) { return function " +
name +
" () { return call(this, arguments) }; };"
)())(Function.apply.bind(fn)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment