On Jun 2, 2015, at 8:08 PM, Logan Smyth wrote: > To clarify things, since I don't think it's been made abundantly clear, the > example that Sebastian gave would work in a standard ES6 environment, > correct? It is only if the callback were executed synchronously that the > exception would be thrown since the `this` binding has not yet been > initialized? > Transpilers however have elected to prevent this to err on the side of > ensuring that invalid ES6 allowed through because adding runtime checking for > the `this` binding would be difficult?
In other words, transpilers have elected to be buggy. ECMAScxript 2015 does not given implementations an option in this regard. If an implementation produces such an early error it is not in compliance with the standard. It doesn't seem like it should be very hard for transpilers to correctly implement the derived constructor this-TDZ semantics. For example, here is a plausible strategy: 1) As a prologue to each constructor body defined in a class definition that includes an extends clause emit: ```js let $$thisAlive = false; let $$this = ()=> { if ($$thisAlive) then return this; else throw ReferenceError"this referenced before super call completes")}; let $$superCalled = r=> $$thisAlive = true, r; ``` 2) compile ever reference to `this` within such constructors as `$$this()`; 3) wrap every call to the super constructor within such constructors as: `$$superCalled(<the emitted code to make the call>)` Allen _______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss