Skip to content

Instantly share code, notes, and snippets.

@jed
Created December 24, 2009 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jed/263294 to your computer and use it in GitHub Desktop.
Save jed/263294 to your computer and use it in GitHub Desktop.
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