Skip to content

Instantly share code, notes, and snippets.

@DavidBruant
Created April 5, 2011 17:52
Show Gist options
  • Save DavidBruant/904114 to your computer and use it in GitHub Desktop.
Save DavidBruant/904114 to your computer and use it in GitHub Desktop.
Default fowarding fix trap
// Object.{freeze|seal|preventExtensions}(proxy) -> proxy
fix: function() {
// As long as target is not frozen, the proxy won't allow itself to be fixed
if (!Object.isFrozen(this.target))
return undefined;
var props = {};
var handler = this;
Object.getOwnPropertyNames(this.target).forEach(function (name) {
var desc = Object.getOwnPropertyDescriptor(this.target, name);
// turn descriptor into a trapping accessor property
props[name] = {
get: function( ) { return handler.get(this, name); },
set: function(v) { return handler.set(this, name, v); },
enumerable: desc.enumerable,
configurable: desc.configurable
};
});
return props;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment