Browse Source

proxy enum/ownKeys test from guide

pull/9/head
Sami Vaarala 11 years ago
parent
commit
b087e9702f
  1. 42
      ecmascript-testcases/test-dev-proxy-enum-ownkeys-guide.js

42
ecmascript-testcases/test-dev-proxy-enum-ownkeys-guide.js

@ -0,0 +1,42 @@
/*
* Proxy enum/ownKeys example in guide.
*/
/*===
foo
bar
foo,bar
foo,bar
===*/
var target = {
foo: 1,
bar: 2,
_quux: 3,
_baz: 4
};
var proxy = new Proxy(target, {
enumerate: function (targ) {
// this binding: handler table
// targ: underlying plain object (= target, above)
return Object.getOwnPropertyNames(targ)
.filter(function (v) { return v[0] !== '_'; });
},
ownKeys: function (targ) {
return Object.getOwnPropertyNames(targ)
.filter(function (v) { return v[0] !== '_'; });
}
});
function test() {
for (var k in proxy) {
print(k); // prints 'foo' and 'bar'
}
}
test();
print(Object.keys(proxy)); // prints 'foo,bar'
print(Object.getOwnPropertyNames(proxy)); // prints 'foo,bar'
Loading…
Cancel
Save