就像你可以拥有:
var obj = {};
obj.a = obj.b = 5;
obj.a === obj.b === 5; //just imagine that it won't evaluate to true === 5对象字面量也有同样的事情吗?大致是这样的:
var obj = {
a : b : 5
};
obj.a === obj.b === 5; //just imagine that it won't evaluate to true === 5发布于 2011-09-06 22:11:17
对象字面量也有同样的事情吗?
不,没有。虽然您可以在:的右侧使用任何其他表达式,包括赋值表达式,但您不能使用另一个属性初始化表达式。而且您不能使用赋值表达式(赋值给该对象的属性之一),因为该对象尚未赋值给目标变量,因此您无法引用它。
https://stackoverflow.com/questions/7321297
复制相似问题