Skip to content

Instantly share code, notes, and snippets.

@joewalker
Created April 4, 2012 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joewalker/2300868 to your computer and use it in GitHub Desktop.
Save joewalker/2300868 to your computer and use it in GitHub Desktop.
proxy default traps
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