In ES6, do for loops with a let/const initializer create a separate scope?
Allen Wirfs-Brock
allen at wirfs-brock.com
Mon Jun 16 12:01:08 PDT 2014
On Jun 16, 2014, at 11:29 AM, Michael Zhou wrote:
> Thanks for the clarification, one detail about the order between incrementing and setting $$lastIteration_i:
> {
> let i = $$lastIteration_i; //create and initialize per iteration i
> if (!(i<10)) break;
> {
> let i;
> }
> i++;
> $$lastIteration_i = i;
> }
>
> Should it be
> $$lastIteration_i = i;
> i++;
>
> instead, given what the spec says?
neither of these desugarings is perfectly in alignment with the actual spec. which doesn't actually use a temp variable in this manner.
A closer match would be:
$$lastIteration_i = i;
$$lastIteration_i++;
The value of the new i for the next iteration is the incremented value of the previous i, but the value of the previous i is not incremented which is important for the cases where a closure has captured the previous i.
Allen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140616/7ebea9f8/attachment.html>
More information about the es-discuss
mailing list