Reputation: 866
I have a JavaScript function that needs to return different objects depending on some variables.
return {
source: fSource,
a: readArray(),
b: readArray()
};
Is there any guarantee that the interpreter assigns the first return value of readArray to a and the second to b? I could easily rewrite it to:
var tmp = {
source: fSource,
};
tmp.a = readArray();
tmp.b = readArray();
return tmp;
But I have a lot of such code and the first notation is quite pretty.
I know that the order of object properties might change but I doubt this affects my case.
Update:
To clarify my concerns:
var a = {
foo: fn1(),
bar: fn2()
};
I don't care about the order of foo and bar in the object. But is it possible that fn2 is called before fn1?
Upvotes: 4
Views: 76
Reputation: 145428
Answering on your update...
The function invocations will go in the same order as you have declared in the code.
Upvotes: 1