brendan at mozilla.com
Thu Jun 23 22:00:39 PDT 2011
On Jun 23, 2011, at 9:49 PM, Mark S. Miller wrote:
> Presently in JS, when seeing a "this", to understand what it means, the eye needs to scan backwards for the closest enclosing occurrence of "function" as a keyword. As this example shows, even this is accident prone. If we introduce multiple special forms that can introduce a this-rebinding boundary, where the new ones are easily missed, we make this burden worse. Is "->" easily missed? (I would guess so.) And if it is, what are we getting in exchange, and is it worth it?
That's a good point if the special forms are not "just syntax" (including some .bind or var self = this rewriting). Arrows at least do not add semantically to the function-like menagerie, so the problem is not different in kind from the one that bit the 'function'-based code you showed. But block lambdas do not have the hazard at all.
If you take your argument to the limit, it wants to kill 'this' (something I believe you wouldn't mind ;-). This could be just another reason to prefer block lambda revival to arrow function syntax.
However, I recall from the last TC39 meeting that some folks on the committee seemed outraged that block lambda revival (because of TCP conformance -- no way around this) lexically binds 'this', always. I believe the problem they had was that they believed shorter function syntax should be neutral on 'this' binding, to make functions in all their current use-cases more convenient.
This is a difference in risk evaluation or tolerance, perhaps. We should try to get to the bottom of it.
More information about the es-discuss