On Fri, Nov 16, 2018 at 12:42 PM Sultan <[email protected]> wrote:
>
> Consistency and sugar. Changing from arrow and non-arrow method is a diff
> between `=>` where:
>
> foo() {} mirrors foo: function () {}
> foo() => {} mirrors foo: () => {}
Yes, but note that the first one *actually contains sugar* - it lets
you omit a decent chunk of characters (at bare minimum, nine) and puts
the name next to the arg-list again, like how normal functions look.
The second lets you omit exactly one character. It also makes it look
*more* like a named function declaration, while arrow functions are
always name-less, so it's not helping you return to a "normal" form
either.
> Also the "this" reference in the second variant is not the class instance i.e
> it is part of the shared prototype.
>
> It has an added reach in usefulness when you consider nested classes:
>
> class A {
> foo() {
> return class B {
> bar() => {
> return this // refers to instance A
> }
> }
> }
> }
>
> This is not possible today without creating a self-like variable for bar to
> reference A's instance; Which is one of the points arrow functions addressed.
Instance methods that don't refer to the instance are definitely the
exception, not the rule. Reading this code, I would *absolutely*
expect on first and probably second glances for `this` to be referring
to the B instance, not the A instance. Binding A's `this` to a
different name is actually a readability *aid* in this circumstance,
unlike the many cases that arrow functions were designed to replace.
This looks to me like a decent argument *against* the suggestion. :/
~TJ
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss