Created
April 4, 2012 12:50
-
-
Save joewalker/2300868 to your computer and use it in GitHub Desktop.
proxy default traps
This file contains hidden or 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
var s = { | |
foo: 'bar' | |
}; | |
for (prop in s) { | |
console.log(prop + '=' + s[prop]); | |
} | |
// foo=bar as expected | |
var proxy = Proxy.create({ | |
get: function(rcvr, name) { | |
return s[name]; | |
} | |
}); | |
console.log('foo=' + proxy.foo); | |
// foo=bar as expected | |
console.log('baz=' + proxy.baz); | |
// baz=undefined as expected | |
try { | |
for (prop in proxy) { | |
console.log(prop + '=' + proxy[prop]); | |
} | |
} | |
catch (ex) { | |
console.log(ex); | |
} | |
// "TypeError: enumerate is not a function", as expected | |
var proxy2 = Proxy.create({ | |
get: function(rcvr, name) { | |
return s[name]; | |
} | |
}, Object.getPrototypeOf(s)); | |
for (prop in proxy2) { | |
console.log(prop + '=' + proxy2[prop]); | |
} | |
// Still an error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment