Named Arrow Functions

Tab Atkins Jr. jackalmage at gmail.com
Tue Aug 11 21:21:46 UTC 2015


On Tue, Aug 11, 2015 at 1:49 PM, Jacob Parker <jacobparker1992 at gmail.com> wrote:
> I did look, but couldn’t find anything on named arrow functions were not included. I do sometimes find cases where I want recursion inside a class function definition, and still need access to `this`. Was it just seen as syntax bloat, or were there any complications to implementing it?
>
> Obviously a contrived example, but something like this (using do syntax too)
>
>     x.map(factorial(x) => do {
>         if (x <= 1) {
>             1;
>         } else {
>             x * factorial(x - 1)
>         }
>     });

Probably not super-helpful in practice, but there's always the Y-combinator. ^_^

let Y = F => (x=>F(y=>(x(x))(y)))(x=>F(y=>(x(x))(y)));

x.map(Y(fact=>x=> do {
  if( x <= 1) {
    1;
  } else {
    x * fact(x-1);
  }
));

Here, the syntax "Y(foo=>" indicates a "named" arrow function.

~TJ


More information about the es-discuss mailing list