Skip to content

Instantly share code, notes, and snippets.

@jed
Created Dec 24, 2009
Embed
What would you like to do?
clones an existing function. scope not included.
function cloneFn( fn ) {
var
str = fn.toString(),
args = str.match( /\((.*)\)/ )[1].split(/\W+/),
body = str.match( /{((?:.|\n)+)}/ )[1];
return Function.apply( this, args.concat( body ) );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment