Lexical versus dynamic "this"

Brendan Eich brendan at mozilla.com
Tue May 10 17:47:51 PDT 2011

On May 10, 2011, at 4:31 PM, Axel Rauschmayer wrote:

> Quoting Andrew Dupont:
>> (b) the ->/=> distinction is, I think, too subtle. Rebinding dramatically changes the meaning of the function, so I'd prefer if the notation guaranteed that a user couldn't gloss over that by mistaking -> for => or vice/versa.
> I agree. Are newbies ever going to be able to handle this? If we are going to overhaul function semantics, wouldn’t it make sense to adopt a more explicit approach?
>> myfunc(param1, param2) -> { ... } // lexical this
>> var obj = {
>>    mymethod: (this, param1, param2) -> { ... } // dynamic this
>> }
> This is how Python handles methods. I think there were objections to this approach, but unfortunately I can neither remember them nor find them online.

No, this was still a possibility and I almost wrote it up at http://wiki.ecmascript.org/doku.php?id=strawman:arrow_function_syntax -- but with (this) -> .... That was just gratuitously overlong and incompatible with CoffeeScript.

There's no arguing with the objection that => feels to close to -> and lexical-this is a major change deserving more significant syntactic differentiation. It's plausible, but if users often need the heavier syntax, they'll waste keystrokes and brain cells on it and curse us for not getting the "right default".

Usability is hard. I've seen zero evidence that CoffeeScript's fat-arrow is unusably terse and people are fooled into thinking it's as cheap as -> (if that's the concern). What is the problem?


More information about the es-discuss mailing list