A few arrow function specification issues

Axel Rauschmayer axel at rauschma.de
Sat Apr 21 13:56:42 PDT 2012

> >>a function shouldn’t work radically (and silently!) different depending on how it is invoked
> every current JS function behaves exactly this way :-)

`this` when not invoking a function as a method:
1. Bearable: this === undefined
2. Nasty: this === window
3. Very nasty: lexical this

> I'm painfully aware that I sound like a broken record on this, but introducing a hard-bound function option while continuing to suport dynamic-bound functions everywhere else is not going to simplify anything.

The point is that dynamic-bound functions will mostly go away in ES.next. There will mainly be methods and arrow functions. With super-references, methods become more than functions with dynamic this, anyway!

> Another function should not need to know how its function arguments were created in order to work properly - thats a terrible anti-functional anti-pattern!

Counter-question: Isn’t it clear when you create a function whether it is going to be a non-method function or a method? What is the use case for a non-method function with dynamic this?

Sometimes you might want to pass a method as a callback, but then you need to convert it to a non-method function, anyway (e.g. via bind()).

Dr. Axel Rauschmayer
axel at rauschma.de

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120421/205ccf49/attachment.html>

More information about the es-discuss mailing list