Arrow functions as methods

Gordon Brander gbrander at
Wed Jul 11 15:51:46 PDT 2012

On Jul 11, 2012, at 2:58 PM, Brendan Eich wrote:
> Irakli Gozalishvili wrote:
>>> If we want convenient unbound-this function syntax, -> stands ready. I proposed it along with
>>> => originally but it was cut by TC39 during our March meeting in order
>>> to achieve consensus on =>.
>> Yeah I'm aware of that, but problem as I see is that new fat arrow functions can not fully replace existing functions.
> That is not a problem, or rather: not a problem with fat arrows.

I would like to loop this conversation away from fat arrow and back to discussing a convenient way to specify flexible `this`.
Irakli suggested:, b)

as sugar for

	foo(o, a, b)

...which is how Python and Lua handle `this`. Treating method invocation as sugar this way allows you to think of `this` as being a category of data on which you operate, rather than a class instance you have access to. It's kind of a functional twist on OOP that makes it easy to write functions that can be used in *both* OO and functional style.

But back to ES... I  think the motivation here may be to a convenient syntax for treating `this` as "soft" so you can assign methods to other objects, or  easily use methods in a functional style. This is sort of how functions work today with call and apply (only you can't pass the call function object around without losing its function context).

I noticed an alternative solution to this problem in the ES Wiki: (see "optional leading `this` initializer"). As I understand it, that would give us some sort of special delimiter for specifying a soft-bound `this` context on a thin-arrow, e.g. in pseudo-code:

	foo(o | a, b)

...or some-such. Irakli, would such a feature resolve your use-case?


More information about the es-discuss mailing list