Is there any way to get something like the following to work in JavaScript? 有什么办法能够使如下内容在JavaScript中起做用? this
var foo = { a: 5, b: 6, c: this.a + this.b // Doesn't work };
In the current form, this code obviously throws a reference error since this
doesn't refer to foo
. 在当前形式中,该代码明显抛出一个参考错误,由于this
不是指foo
。 But is there any way to have values in an object literal's properties depend on other properties declared earlier? 可是, 是否有任何方法能够使对象文字的属性值取决于先前声明的其余属性? spa