Are Javascript Object Properties assigned in order?

javascript

Solution

Standard ECMA-262 (5.1) - Section 11.1.5 - Object Initialiser

The production PropertyNameAndValueList : PropertyNameAndValueList , PropertyAssignment is evaluated as follows:

1. Let obj be the result of evaluating PropertyNameAndValueList.
2. Let propId be the result of evaluating PropertyAssignment.
...
5. Call the [[DefineOwnProperty]] internal method of obj with arguments propId.name, propId.descriptor, and false.
6. Return obj.

So yes, the order is enforced by the standard.

Problem

Say I have an object which assigns properties based off the return value of a function: ``` var i = 0; var f = function() { return ++i; } var foo = { a:f(), b:f(), c:f() }; ``` Is it guaranteed that foo.a will be 1, foo.b will be 2, and foo.c will be 3? I know that JS doesn't guarantee order when you iterate over an object, what about assignment? Is it specified in the JS specification somewhere? I'm only asking for educational reasons. Thanks.

Original source