On Feb 6, 4:23 am, Christophe Grand <[EMAIL PROTECTED]> wrote:
> Hello,
>
> These two snippets:
>    for each (var i in Iterator(aJavaMap.entrySet)) print(i);
> and:
>    for (var i in Iterator(aJavaMap.entrySet)) print(i);
> print the same results.
>
> But when I try to destructure into key and value:
>    for each (var {key: k, value: v} in Iterator(aJavaMap.entrySet))
> {print(k); print(v)}
> works but:
>    for (var {key: k, value: v} in Iterator(aJavaMap.entrySet))
> {print(k); print(v)}
> fails with:
>
> > Left hand side of for..in loop must be an array of length 2 to accept 
> > key/value pair.
>
> Ok, it makes sense but I find it somewhat inconsistent: wouldn't it be
> better to make
>    for (var i in Iterator(aJavaMap.entrySet)) print(i);
> to return a synthetic counter or to throw an exception?
>
> Christophe Grand

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

--N
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to