Created
April 19, 2011 18:30
-
-
Save seaneagan/929185 to your computer and use it in GitHub Desktop.
Proxy internal state API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Proxy.ForwardingHandler.prototype = { | |
create: function(target) {return {target: target}}, | |
getPrototypeOf: function (proxy, state) { | |
return Object.getPrototypeOf(state.target); | |
} | |
// all other traps take state argument | |
}; | |
// ... // | |
var target = {}, h = new Proxy.ForwardingHandler, P = Proxy.Constructor(h), p = P(target); | |
// changing one trap | |
h.set = function(...args){ | |
console.log("New set trap in forwarding proxy. Property name: " + args[1]); | |
Proxy.ForwardingHandler.set.apply(this, args); | |
}; | |
// ... // | |
p.ProxiesAreAwesome = 42; | |
// logs: "New set trap in forwarding proxy. Property name: ProxiesAreAwesome" | |
target.ProxiesAreAwesome; // 42. Forwarding went well too |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment