Skip to content

Instantly share code, notes, and snippets.

@appden
Created December 3, 2009 09:23
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appden/248013 to your computer and use it in GitHub Desktop.
Save appden/248013 to your computer and use it in GitHub Desktop.
// Puncture a closure, absolute madness
Function.prototype.puncture = function(){
var wormhole = function(__cmd__){
return eval(__cmd__);
};
var source = ('' + this).match(/function.+?\{([\s\S]*)\}/)[1];
var fn = new Function('this.wormhole=' + wormhole + '\n' + source);
fn.prototype = this.prototype;
for (var prop in this){
if (this.hasOwnProperty(prop)) fn[prop] = this[prop];
}
return fn;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment