Fw: lexical 'super' in arrow functions?

Claus Reinke claus.reinke at talk21.com
Mon Dec 3 01:37:43 PST 2012

>>  Is 'super' currently limited to method bodies, excluding local functions?
> "super" is limited to ClassBody

Yes, the question is about arrow functions in ClassBody.

>>> Given that 'this' is lexical in arrow functions, I expected any enclosing
>>> 'super' to be available, as well, but I cannot confirm this from the spec.
> Can you clarify... did you mean something like:
> class Mine extends Array {
>  constructor(...args) {
>    this.foo = () => {
>  super(...args);
>    };
>  }
> }

More likely in a non-constructor method, but yes.

>>> This is from listening in on some of the TypeScript traffic, where people
>>> are running into all kind of issues when trying to use ES6 classes, btw.
> I've been following all of the tickets and offering support wherever I
> can—I'd love to see the specific cases that you're referring to.

The majority of cases are just standard 'this' confusion, where the use
of class syntax somehow gives people the impression that they don't
have to worry about such aspects of JS.

Slightly more interesting are cases where class syntax is combined with
method borrowing, often in higher-order function calls, losing the 'this'
context while still inside the class body, ie

    class { m1() { return this}; m2() { return [1,2].map(this.m1) }}

Both the above can usually be worked around by wrapping in arrows
(eta-expansion), avoiding the depths of .bind/.call, and staying within
the nice new higher-level syntax. I assume you've seen those discussions.

In the case that triggered this thread, the arrow wrapper does not
work because TS currently takes a narrow view of where 'super' is
permitted, excluding arrow functions nested in class bodies:



More information about the es-discuss mailing list