Are Javascript Object Properties assigned in order?

前端 未结 5 894
深忆病人
深忆病人 2020-12-03 14:11

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 = {
                  


        
5条回答
  •  盖世英雄少女心
    2020-12-03 14:24

    Yes, you are guaranteed that a will be 1, b will be 2, etc. Each f() will be interpreted in the order you wrote them.

提交回复
热议问题