Skip to content

Class member arrow functions #4931

Answered by aduh95
texels asked this question in Q&A
May 6, 2022 · 0 comments · 2 replies
Discussion options

You must be logged in to vote

I think that's because the Babel plugin you were using was not ECMAScript compliant, super.onError cannot refer to a class field function:

const arrowFn = () => {};
class Parent {
  t() {} // Prototype method.
  t = arrowFn; // Class field.
}

new class extends Parent {
  t = () => console.log(
    super.t === Parent.prototype.t, // super.t refers to the prototype method
    super.t !== arrowFn, // not to the arrow function defined property
  );
}().t();

console.log(new Parent().t === arrowFn); // even though the class field has "higher priority" in other context.

Is this a bug or going to be changed in the future?

The proposal has reached stage 4 and has been merged to the ECMAScript …

Replies: 0 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@texels
Comment options

Answer selected by texels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants