For-Each Loop AS3:方向有保证吗? [英] For-Each Loop AS3: Is the direction guaranteed?

查看:16
本文介绍了For-Each Loop AS3:方向有保证吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 AS3 中 Array、Dictionary 和 Object 类型的迭代顺序,包括 for-each 和 for-in 循环.还有哪些因素可以改变这些循环类型组合的迭代顺序?

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 iteration order of these loop type combinations?

例如,我假设在 Array 类型上使用 for-each 总是从第一个元素移动到最后一个元素.For-each 不能在 Dictionary 上使用,那么如何使用 for-in 循环确定顺序?

For example I presume that using a for-each on an Array type always move from the first element to the last. For-each cannot be used on a Dictionary so how is the order determined using a for-in loop?

推荐答案

你的意思是 for (x in y) 类型的 for-each 循环吗?AS3 规范说 for 循环具有与 ECMA-262 第 3 版和 E4X 中定义的相同的语法和语义".

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,第 12.6.4 节声明枚举的顺序由对象定义"——换句话说,它取决于您是否在遍历列表、字典、数组等.

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...

不幸的是,规范声明枚举属性的机制 [...] 取决于实现."我在 Array 文档中看不到任何指定排序的内容.老实说,这有点不令人满意:(

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 :(

这篇关于For-Each Loop AS3:方向有保证吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆