Intentional breaking change in ES6 draft spec?

Allen Wirfs-Brock allen at wirfs-brock.com
Fri Jun 14 09:06:35 PDT 2013


On Jun 14, 2013, at 12:01 AM, Andy Wingo wrote:

> On Fri 14 Jun 2013 04:24, Luke Hoban <lukeh at microsoft.com> writes:
> 
>> (I believe this introduces the only place that "var x" is allowed but
>> cannot have an initializer?).
> 
> FWIW, there are similar situations in the same spot of the grammar: "let
> x" can't have an initializer in for-of or for-in, and neither can "var
> x" in for-of.
> 

Yes, and this was one of the consistency motivation to the var change.

for (const x = c of foo) ...
for (const x = c  in foo) ...

simply woundn't work if x could have an initializer because a const can't be initialized twice.

for (let x of foo) ...
fpr (let x in foo) ...

with an initializer would suggest that the per iteration binding of x is initialized with the initialization expression.  Is the initialization expression evaluated once or at the beginning of each iteration?

It is a simpler overall story to just not allow pointless initializers on declarations in for-in/for-of statements.  The fact that we could find no dependencies upon for-in var initializers gave us confidence about introduce the breaking change for var.

Allen 



More information about the es-discuss mailing list