On Fri, Jul 15, 2016 at 7:18 AM, Allen Wirfs-Brock <[email protected]>
wrote:
> This is by design. ECMAScript block scoped declarations generally conform
> to the principle that within a single block or statement a name may have
> only a single binding. For example,
>
> ```js
> let x=0;
> {
> let x = x+1; //access to uninitialized variable error because both the
> RHS and LHS refer to the inner x
> //which has not yet been initialized when the RHS is
> evaluated
> }
>
> ```
>
> The same principle also applies to
> ```js
> let n = {a:[]};
> for (let n of n.a) ;
> ```
>
> although the actual scoping of the `for` statement is more complex.
> Basically, such `for` statements consider all names bound by the `let` part
> of of the `for` header to be undefined while the `of` expression is being
> evaluated.
>
>
Wouldn't that scope for the 'for' loop declaration allow testing the 'n'
variable after the loop? (test to see if it was broken out of completed),
without requiring extra braces around the for? (Although sounds like just
dong
{
for( let n ...) {
}
// can test/use N here?
}
would also have worked like the workaround for C#/C++?
> This is done to avoid any confusion about which `n` the expression
> references. Such confusion is avoid by all references to the `let` bound
> names from the RHS errors.
>
> Allen
>
>
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss