> I am in agreement with Angus on this one.
> 
> If there is no skinny arrow, hard |this| binding should not be part of the 
> spec. Fat arrow functions should default to lexical |this|, but if there is 
> no skinny arrow, it should not be a hard binding and call/apply should be 
> allowed, as well as bind,

IMHO, the spec got it exactly right. We have a chance to really simplify things 
and introduce a clear distinction:

- Methods – dynamic `this`: Use a concise method definition inside an object 
literal (or, hopefully, inside a class declaration).
- Non-method functions – lexical `this`: Use an arrow function.

Anything else is rare (see Kevin Smith’s JS code survey) and non-methods with 
dynamic this are usually an anti-pattern. If you really need it, there are 
always old-school functions.


As for switching between dynamic `this` and lexical `this` depending on whether 
a function is called as a method or as a function. At first glance, it sounds 
like a good idea, like the best of both worlds. However, I’m with Domenic 
Denicola: it’s too brittle – a function shouldn’t work radically (and 
silently!) different depending on how it is invoked. Switching to this = 
undefined is bearable for old-school non-method functions, but switching to 
lexical this will lead to many hard-to-debug errors.

-- 
Dr. Axel Rauschmayer
[email protected]

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to