TypeError: 'ownKeys' on proxy: trap result did not include 'arguments'
TypeError: 'ownKeys' on proxy: trap result did not include 'arguments'
它想从我这里得到什么?如何让它发挥作用?
var proxy_handler =
{
ownKeys: function(target)
{
return Object.keys(target.data)
},
}
var proxxxy = function(initial_data)
{
var return_value = "Goodbye world"
var target = function() { return return_value }
if(typeof initial_data == "undefined")
{
target.data = {}
}
else
{
target.data = initial_data
}
return new Proxy(target, proxy_handler)
}
var p = proxxxy({q:"aaa",w:"bbb",f:"ccc"})
console.log(p())
console.log(Object.getOwnPropertyNames(p))
它打印错误,但它不应该:
me@me:~/tst$ node --version
v6.2.2
me@me:~/tst$ node test3.js
Goodbye world
/home/me/tst/test3.js:26
console.log(Object.getOwnPropertyNames(p))
^
TypeError: 'ownKeys' on proxy: trap result did not include 'arguments'
at Object.<anonymous> (/home/me/tst/test3.js:26:24)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.runMain (module.js:575:10)
at run (node.js:348:7)
at startup (node.js:140:9)
at node.js:463:3
这是一个错误吗?如果是这样 - 我可以在哪里提交它?
这不是错误;此行为由 proxy spec for ownKeys
,步骤 17a 定义。用简单的英语来说,实际 target
的任何不可配置的 属性 都必须出现在 ownKeys
返回的属性列表中,因此您的示例中缺少 arguments
:
> Object.getOwnPropertyDescriptor(target, "arguments")
Object {value: null, writable: false, enumerable: false, configurable: false}
它想从我这里得到什么?如何让它发挥作用?
var proxy_handler =
{
ownKeys: function(target)
{
return Object.keys(target.data)
},
}
var proxxxy = function(initial_data)
{
var return_value = "Goodbye world"
var target = function() { return return_value }
if(typeof initial_data == "undefined")
{
target.data = {}
}
else
{
target.data = initial_data
}
return new Proxy(target, proxy_handler)
}
var p = proxxxy({q:"aaa",w:"bbb",f:"ccc"})
console.log(p())
console.log(Object.getOwnPropertyNames(p))
它打印错误,但它不应该:
me@me:~/tst$ node --version
v6.2.2
me@me:~/tst$ node test3.js
Goodbye world
/home/me/tst/test3.js:26
console.log(Object.getOwnPropertyNames(p))
^
TypeError: 'ownKeys' on proxy: trap result did not include 'arguments'
at Object.<anonymous> (/home/me/tst/test3.js:26:24)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.runMain (module.js:575:10)
at run (node.js:348:7)
at startup (node.js:140:9)
at node.js:463:3
这是一个错误吗?如果是这样 - 我可以在哪里提交它?
这不是错误;此行为由 proxy spec for ownKeys
,步骤 17a 定义。用简单的英语来说,实际 target
的任何不可配置的 属性 都必须出现在 ownKeys
返回的属性列表中,因此您的示例中缺少 arguments
:
> Object.getOwnPropertyDescriptor(target, "arguments")
Object {value: null, writable: false, enumerable: false, configurable: false}