Consistency and sugar. Changing from arrow and non-arrow method is a diff
between `=>` where:
foo() {} mirrors foo: function () {}
foo() => {} mirrors foo: () => {}
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.
On Fri, Nov 16, 2018 at 11:15 PM Isiah Meadows <[email protected]>
wrote:
> Not sure what the benefit here is:
>
> - You can do `foo: () => bar` for objects
> - You can do `foo = () => bar` for class instances using the public fields
> proposal.
>
> This leaves out self-binding, but you could always use a local variable if
> necessary. (It's like one extra line, maybe 3, and it's not common at all.)
> On Fri, Nov 16, 2018 at 15:09 Sultan <[email protected]> wrote:
>
>> The missing colon ":" is intentional.
>>
>> On Fri, Nov 16, 2018 at 10:57 PM J Decker <[email protected]> wrote:
>>
>>>
>>>
>>> On Fri, Nov 16, 2018 at 11:23 AM Sultan <[email protected]> wrote:
>>>
>>>> As the name suggests; An update to the grammar related to methods on
>>>> objects/classes to support arrow methods:
>>>>
>>>> today: {render() { return 'Hello' }}
>>>> proposed addition: {render() => 'Hello'}
>>>>
>>>> proposed addition: {render:() => 'Hello'}
>>>
>>>
>>>> This could be some-what linked to class fields in the class variant;
>>>> That is what does "this" refer to when used in a class.
>>>> _______________________________________________
>>>> es-discuss mailing list
>>>> [email protected]
>>>> https://mail.mozilla.org/listinfo/es-discuss
>>>>
>>> _______________________________________________
>> es-discuss mailing list
>> [email protected]
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss