restrictions on let declarations

Rick Waldron waldron.rick at gmail.com
Thu Jan 30 08:51:03 PST 2014


On Thu, Jan 30, 2014 at 11:39 AM, John Lenz <concavelenz at gmail.com> wrote:

> How did "let x" in for-loops land:
>
> for (let x = 1; x < 10 ; i++) {
>   // is "x" a fresh binding for every iteration?
>

Yes.


> }
>
> This wouldn't be "block" scoping either.
>

See:
https://github.com/rwaldron/tc39-notes/blob/master/es6/2013-11/nov-20.md#consensusresolution-6


Rick



>
> On Thu, Jan 30, 2014 at 8:13 AM, Brendan Eich <brendan at mozilla.com> wrote:
>
>> John Barton wrote:
>>
>>
>>> On Thu, Jan 30, 2014 at 7:54 AM, Brendan Eich <brendan at mozilla.com<mailto:
>>> brendan at mozilla.com>> wrote:
>>>
>>>     John Lenz wrote:
>>>
>>>         Generally, I've always thought of:
>>>
>>>         "if (x) ..." as equivalent to "if (x) { ... }"
>>>
>>>
>>>     let and const (and class) are block-scoped. {...} in your "if (x)
>>>     {...}" is a block. An unbraced consequent is not a block, and you
>>>     can't have a "conditional let binding".
>>>
>>>     The restriction avoids nonsense such as
>>>
>>>     let x = 0; { if (y) let x = 42; alert(x); }
>>>
>>>     What pray tell is going on here, in your model?
>>>
>>>
>>> I'm with John: the alert should say 0 and I can't see why that is not
>>> obvious.
>>>
>>
>> Interesting!
>>
>> You don't want the alert to show undefined, so the extent of the inner
>> binding in your model is the unbraced consequent of the  "if".
>>
>> That is not "block scope" in any plain sense.
>>
>> /be
>>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140130/e316e6d1/attachment.html>


More information about the es-discuss mailing list