return when desugaring to closures

Brendan Eich brendan at
Mon Oct 13 15:34:37 PDT 2008

On Oct 13, 2008, at 1:16 PM, David-Sarah Hopwood wrote:

> In the "i++", which iteration's 'i' is the LeftHandSideExpression
> referring to? Or does this expand to something like:
>  let ($i = 0) {
>    for (;
>         let (i = $i) {i < 10};
>         let (i = $i) {{i++;} $i = i;}} {
>      let (i = $i) {...};
>    }
>  }
> ? That would work as I think you want, but it seems a bit magical to  
> me.

On the contrary, what's magical is when one stores i in elements of an  
array, or calls setTimeout (example in 
, and the results are all the last value of the loop variable.

This has been a frequent source of confusion and complaints -- a bug,  
in short.

Doing it the way Mark proposes fixes the bug, and has no other bad  
effects that I can see (but we'll have to implement and user-test to  
be sure).

> I could be convinced, though -- do you want to try and make the case  
> for
> why there should be a fresh variable per iteration with some concrete
> examples?


More information about the Es-discuss mailing list