Norris Boyd a écrit :
> I don't see the issue with "for (var i in Iterator(aJavaMap.entrySet))
> print(i);" working the way it does. I do think the behavior of "for"
> vs. "for each" is at least odd if not wrong.

We are in agreement: the current behaviour is weird. [1]

To me, "for in" means "iterate over property names or key-value pairs" 
and "for each in" means "iterate over values" but I would be happy with 
any semantics as long as they are coherent.

> I've posted to
> mozilla.dev.tech.js-engine group about it since I can get similar
> behavior on a non-Java iterator example.

Ok, thanks!

Christophe

[1] : And it gets worse if the iterator yields arrays: you can 
deconstruct only the first two elements in the for..in construct:

js> function entries() { yield ["a", 1, "A"]; yield ["b", 2, "B"]; }
js> for (var [k, v] in entries()) print(k,v);
a 1
b 2
js> for each(var [k, v] in entries()) print(k,v);
a 1
b 2
js> for (var [k, v, K] in entries()) print(k,v,K);
js: "<stdin>", line 19: Left hand side of for..in loop must be an array 
of length 2 to accept key/value pair.
js> for each (var [k, v, K] in entries()) print(k,v,K);
a 1 A
b 2 B
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to