Javascript object initialization and evaluation order
问题 If I write var a = [1,2]; var b = { foo: a.pop(), bar: a.pop() }; What is the value of b , according to the specification? (By experiment, it's {foo: 2, bar: 1} , but I worry whether this is implementation-specific.) 回答1: See ECMAScript section 11.1.5 defining how the ObjectLiteral production is parsed. In particular: PropertyNameAndValueList , PropertyName : AssignmentExpression is evaluated as follows: Evaluate PropertyNameAndValueList. Evaluate PropertyName. Evaluate AssignmentExpression.