what kind of problem is this fat arrow feature trying to solve ?

Andrea Giammarchi andrea.giammarchi at gmail.com
Wed Oct 2 16:22:37 PDT 2013


I honestly think that is a new model to explain out there, and for a
language many misunderstood already because of the magic `this` behavior
... fat arrow introduces a whole new world of foot-guns and a third option
over inheritance and/or mixins.

The fact you need a lot of bind in the DOM suggests me you were not
familiar or did not consider the handleEvent approach that really
simplifies that a lot. If this is not the case than yes, fat arrow is
useful for you.

This just to say that I am not saying it won't help, I am trying to
understand where it does.

Thanks


On Wed, Oct 2, 2013 at 3:12 PM, Aymeric Vitte <vitteaymeric at gmail.com>wrote:

>  Andrea, it's difficult to understand why you think the fat arrow does not
> help or I misunderstood your point, if |this| is already bound to
> something, like for events, then you don't need it, if you want to bind to
> something else then you use bind, if you want to bind to the outer |this|
> then you use the fat arrow, that's extremely usefull, even in a DOM env,
> because for example while handling events you probably have the case of
> binding |this| again inside, but DOM is not only events, I am using a lot
> bind(this) in DOM, node, etc and will replace it as previously mentioned by
> the fat arrow when available.
>
> Regards,
>
> Aymeric
>
> Le 02/10/2013 20:11, Andrea Giammarchi a écrit :
>
> You need to be sure about the `this` because today you can `bind(anyObject
> || this)` while with fat arrow you can only bind `this` so you need to be
> sure that the function context, the one everybody has always borrowed
> through call and apply, is the one you expect to be.
>
>  In a new direction where instanceof is being discouraged, the usage of
> this become critical.
>
>  As shortcut, fat arrow fails. `var o = {method: () => whatver;};`
>
>  As DOM listener it brings what `handleEvent` does since ever.
> ```javascript
> var o = {
>   init: function () {
>     document.addEventListener('click', this);
>     // virtually the same of
>     document.addEventListener('click', (e) => this.handleEvent(e));
>   },
>   handleEvent: function () {
>     this === o;
>   }
> };
> ```
>
>  So I don't see many advantages on DOM world.
>
>  Once again, I am trying to understand where is the glory of this new
> feature.
>
>  I am not saying it should not be there, ES6 classes and generators
> already breaks the old syntax so it won't hurt a new utility as fat arrow
> is but where this will be exactly a better approach to the current
> situation ?
>
>  The only one that comes into my mind is the `once` event listener in
> node or eddy.js ... but `once` a part, and I admit in there it's handy, I
> cannot see many other real/concrete usages.
>
>  In CoffeeScript the fat arrow behaves differently having a dynamic this,
> am I correct?
> So whoever is comparing fat arrow with CoffeeScript should be aware these
> are completely different beasts and there was my question about what is
> solving for the real world.
>
>  No need to talk about use strict.
>
>  Thanks
>
>
>
>
>
> On Wed, Oct 2, 2013 at 11:01 AM, Brendan Eich <brendan at mozilla.com> wrote:
>
>> Andrea Giammarchi wrote:
>>
>>> fat arrow does not add any capabilities but create the need to be sure
>>> about the context.
>>>
>>
>>  This does not make sense. The problem of being unsure about "which this"
>> already exists. Adding arrows does not make it worse. The new syntax makes
>> it better, compared to 'var self = this;' or .bind(this) hacks that are
>> more verbose and easy to forget -- that is, whose absence is easy to
>> overlook.
>>
>>
>>  In use strict fat arrow will bring a lovely `undefined` wich is
>>> undesired so nothing is solved in there.
>>>
>>
>>  Stop comparing apples to oranges. If we have today
>>
>> "use strict";
>> function foo() {
>>   ...
>>   setCallback(function () { ... this ...}.bind(this));
>> }
>>
>>
>> Then you have no greater or lesser incidence of undefined-this bugs due
>> to someone calling foo() instead of foo.call, foo.apply, or obj =
>> {method:foo}, obj.method() by changing this code to use an arrow:
>>
>> "use strict";
>> function foo() {
>>   ...
>>   setCallback(() => {... this ...});
>> }
>>
>>
>> If you don't like strict mode, keep that out of this thread. Incidence of
>> undefined-this bugs due to it do not change with arrows.
>>
>> /be
>>
>
>
>
> _______________________________________________
> es-discuss mailing listes-discuss at mozilla.orghttps://mail.mozilla.org/listinfo/es-discuss
>
>
> --
> Peersm : http://www.peersm.com
> node-Tor : https://www.github.com/Ayms/node-Tor
> GitHub : https://www.github.com/Ayms
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131002/4f99f217/attachment.html>


More information about the es-discuss mailing list