【发布时间】:2018-03-30 02:23:05
【问题描述】:
基本上我需要能够做到这一点:
var obj = {"foo":"bar"},
arr = [];
with( obj ){
arr.push( foo );
arr.push( notDefinedOnObj ); // fails with 'ReferenceError: notDefinedOnObj is not defined'
}
console.log(arr); // ["bar", ""] <- this is what it should be.
我正在寻找 {}.__defineGetter__ 或 {get} 的“全局”等效项,以便为所有未定义的属性获取器返回一个空字符串(请注意,这与 undefined 的属性不同)。
【问题讨论】:
-
你能用proxy吗?
-
看起来
Proxy在任何节点版本中都不可用。 :-( -
是的。看起来 V8 是still working on it。
-
Proxy在 0.7.8 上可用,带有 --harmony 命令行标志。 -
并且(一辆越野车)
Proxy在节点 0.6.18 中通过--harmony_proxies标志可用。
标签: javascript node.js