Skip to content

Instantly share code, notes, and snippets.

@getify
Created March 18, 2011 17:07
Show Gist options
  • Select an option

  • Save getify/876439 to your computer and use it in GitHub Desktop.

Select an option

Save getify/876439 to your computer and use it in GitHub Desktop.
var function_sandbox = (function(global) {
function SubFunc(func) {
func.__proto__ = funcPlugin;
return func;
}
var funcPlugin, __Function = global.Function;
// make prototype values conform to ECMA spec and inherit from regular natives
(SubFunc.prototype = new __Function('')).__proto__ = __Function.prototype;
// assign constructor property
(funcPlugin = SubFunc.prototype).constructor = SubFunc;
return SubFunc;
})(this);
@getify
Copy link
Copy Markdown
Author

getify commented Mar 18, 2011

Usage:

function blah() { /*...*/ }
var foo = function_sandbox(blah);
foo(/*...*/); // works, and it's checkable if `foo` is overriden to not actually be `blah`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment