On 27 December 2012 21:08, David Herman <dher...@mozilla.com> wrote: > On Dec 27, 2012, at 1:23 AM, Andreas Rossberg <rossb...@google.com> wrote: > >> var x; > >> if (...) { x = ... } > >> if (x === undefined) { ... } > >> > >> If you want to use let instead, the === if-condition will throw. You > would instead have to write: > >> > >> let x = undefined; > >> if (...) { x = ... } > >> if (x === undefined) { ... } > > > > That is not actually true, because AFAICT, "let x" was always understood > to be equivalent to "let x = undefined". > > Well that's TDZ-UBI. It *is* true for TDZ-RBA. Maybe I was the only person > who thought that was a plausible semantics being considered, but my claim > (P => Q) is true. Your argument is ~P. Anyway, one way or another hopefully > everyone agrees that TDZ-RBA is a non-starter. >
Even with TDZ-RBA you can have that meaning for "let x" (and that semantics would be closest to 'var'). What TDZ-RBA gives you, then, is the possibility to also assign to x _before_ the declaration. But anyway, I think we agree that this is not a desirable semantics, so it doesn't really matter. > It's true that with TDZ, there is a difference between the two forms > above, but that is irrelevant, because that difference can only be observed > for erroneous programs (i.e. where the first version throws, because 'x' is > used by 'stmt'). > > Can you prove this? (Informally is fine, of course!) I mean, can you prove > that it can only affect buggy programs? > Well, I think it's fairly obvious. Clearly, once the assignment/initialization "x = e" has been (successfully) executed, there is no observable difference in the remainder of the program. Before that (including while evaluating e itself), accessing x always leads to a TDZ exception in the first form. So the only way it can not throw is if stmt and e do not access x, in which case the both forms are equivalent. /Andreas
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss