return when desugaring to closures

Brendan Eich brendan at
Mon Oct 13 15:31:11 PDT 2008

On Oct 13, 2008, at 8:43 AM, Mark S. Miller wrote:

> On Mon, Oct 13, 2008 at 8:05 AM, David-Sarah Hopwood
> <david.hopwood at> wrote:
>> "for (var ...)" implicitly introduces a block whether or not it
>> is a substatement. This is a wart of C++/C99/Java syntax that
>> we have to live with, since too much code relies on it.
> Yes, but how do we live with it? The only currently allowed case,
> "var" as above, is no problem, since it hoists to the function body
> anyway. But what about "let". Do we all agree that in
>    for (let x = ...) {...x...}
>    ... x ...
> the x after the for loop does not refer to the x defined by the for
> loop? In that case, no problem with for being a SubStatement.

No one ever proposed otherwise for for (let...), and it would be nuts  
to do anything like that.

> A remaining interesting question is whether the for loop reassigns to
> a single per-for-loop-entry x, or whether it initializes a fresh
> per-iteration x. If the for loop body has a closure that captures x,
> it makes a difference. I recommend the per-iteration view. If we can
> agree quickly on per-iteration, then
>    for (const x = ...) {...x...}
> should be allowed in ES3.1 (whether or not const hoists to block
> start). After ES3.1
>    for (const i :T[i] = ...) {...; a[i] = function(){...i...}; ...}
> would then mean what it should mean. Cool.

Agreed. See --  
which is a bug we'd like to fix by following a spec.


More information about the Es-discuss mailing list