Arrow functions as methods

Brendan Eich brendan at mozilla.org
Wed Jul 11 23:02:35 PDT 2012


Gordon Brander wrote:
> I noticed an alternative solution to this problem in the ES Wiki:http://wiki.ecmascript.org/doku.php?id=harmony:arrow_function_syntax#deferred  (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.

That syntax was for expressions and definitions of functions, not for 
calls. The idea was to enable parameter default values for |this|. It 
won't do what Irakli wants.

Soft-bind is not going to fly, see

https://mail.mozilla.org/pipermail/es-discuss/2012-June/023221.html,
https://mail.mozilla.org/pipermail/es-discuss/2012-June/023202.html, and 
mainly
https://mail.mozilla.org/pipermail/es-discuss/2012-May/023002.html.

Implicitly shifting |this| in call expressions to the front of the 
actual argument list is similarly painful in overhead for implementors, 
besides making the dynamic "two args, or only one?" hazard depending on 
how a callee called from a polymorphic site happened to be expressed.

What Python does is a bit different:

obj.foo(arg)

is

Class_of_obj.foo(obj, arg)

not just

foo(obj, arg)

for some identifier-expression 'foo'. But this depends on classes in 
Python, which are not in any way analogous to => function expressions.

/be




More information about the es-discuss mailing list