Skip to content

Instantly share code, notes, and snippets.

Created Dec 24, 2009
What would you like to do?
clones an existing function. scope not included.
function cloneFn( fn ) {
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