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 <[email protected] <mailto:[email protected]>> 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 list
[email protected]
https://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

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

Reply via email to