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:

http://stackoverflow.com/questions/13617130/wrong-this-when-calling-a-superclass-method-from-a-callback-in-a-subclass-in-t/13629680#13629680

Claus


_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to