尝试编译:
var object:Object = {};
object.one = "foo";
object.two = "foo";
object.three = "foo";
object.four = "foo";
for(var key:String in object)
{
trace(key);
}
...您将获得:
... you will get:
one
four
two
three
为什么搞砸了订单?
Why the messed up order?
对象的键没有顺序。如果您需要preserve秩序,有查找,那么你需要创建一个自定义集合,提供了该功能。
The keys of an object are not ordered. If you need to preserve order and have a lookup, then you need to create a custom collection that provides that functionality.