On 5 June 2014 18:50, Allen Wirfs-Brock <[email protected]> wrote: > Over and beyond the breaking change WRT function, I really don’t see the > value in such a restriction. There are many pointless or nonsensial things > that can be written as expressions. In general, we don’t complicate the > language to make such things illegal.
The point is not so much that it is pointless or nonsensical, but that it has surprising and arguably inconsistent meaning. /Andreas > On Jun 5, 2014, at 7:58 AM, Andreas Rossberg <[email protected]> wrote: > >> C-style for-loops allow declarations as init statements, but only some >> of them. Yet, the others (function and class) are actually >> syntactically legal in that position as well, because they are simply >> parsed as expressions. Consider: >> >> let x = 0 >> for (let x = 1; ;) x // 1 >> for (const x = 1; ;) x // 1 >> for (function x(){}; ;) x // 0 >> for (class x(){}; ;) x // 0 >> >> I think these latter two examples violate the principle of least >> surprise. I wonder if it wouldn't be cleaner to rule them out, by >> imposing the same lookahead restrictions on for-loop init expressions >> as there are for expression statements. >> >> The one caveat is that for function, that would actually be a breaking >> change, but is it likely to be a real world one? >> >> What do you think? >> >> /Andreas >> _______________________________________________ >> 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

