I'm wrapping an object in a Proxy and then iterate through it. How can I control the keys it iterates through?
The proxy works if I don't override the keys:
var obj = {"hello": "world"}
var proxy = new Proxy(obj, {})
for (var key in proxy){
console.log(key)
}
// logs "Hello"
However, nothing is logged if I change the keys in the ownKeys handler.
var obj = {"hello": "world"}
var proxy = new Proxy(obj, {
ownKeys: function(){
return ["a", "b"]
}
})
for (var key in proxy){
console.log(key)
}
// Logs nothing
If I return "hello" as part of the ownKeys only "hello" is logged.
Apparently there was an enumerate trap in ES6, but it has been removed from ES7.
Is it still possible to control the for...in loop with a Proxy? Why was enumerate removed from the spec?
