My friend Iacob showed me an interesting livedocs comment on the Performing Object Introspection page. It seems that if you try to change values while you are in a for loop, everything kind of gets messed up.
For example take the following code :
For instance:
var obj : Object = {};
obj.a = "x";
obj.b = "y";
obj.c = "z";
for(var key:String in obj){
obj[key] = obj[key]+"x";
trace(key+"="+obj[key]);
}
1. | var obj : Object = {}; |
2. | obj.a = "x"; |
3. | obj.b = "y"; |
4. | obj.c = "z"; |
5. | for(var key:String in obj){ |
6. | obj[key] = obj[key]+"x"; |
7. | trace(key+"="+obj[key]); |
8. | } |
produces:
a=xx
a=xx
c=zx
The most interesting thing I found is that you can use the new Object() instead of {} and it works fine.
If you do another for right after that and just trace the output you see that properties a and c were affected (and show once) while property b was not affected by the previous for (not changed).
Weird, but as I said, you can use new Object() instead of the curly brackets {} to get rid of this problem.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment