For-Each Loop AS3: Is the direction guaranteed?

前端 未结 3 655
暗喜
暗喜 2020-12-11 15:33

I would like to know the iteration order for the Array, Dictionary and Object types in AS3, for both the for-each and the for-in loops. Also what factors can change the iter

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-11 16:15

    Do you mean the for (x in y) type of for-each loop? The AS3 specification says that for loops "have the same syntax and semantics as defined in ECMA-262 edition 3 and E4X".

    ECMA-262, section 12.6.4 state that "the order of enumeration is defined by the object" - in other words, it will depend on whether you're iterating through a list, a dictionary, an array etc.

    I would hope that the documentation for most collections will explicitly state the enumeration order (or that the order isn't defined) but I haven't checked...

    EDIT: Unfortunately the specs state that "the mechanics of enumerating the properties [...] is implementation dependent." I can't see anything in the Array docs to specify ordering. It's a bit unsatisfactory, to be honest :(

提交回复
热议问题