JS (intermediate value).g is not a function 使用超级运算符时中间值不是函数

JS (intermediate value).g is not a function intermediate value is not a function when using super operator

我试图从 JS 中的匿名函数调用 super,但出现以下错误:

Uncaught TypeError: (intermediate value).g is not a function

下面的代码有什么问题?

class A {
    m() {
      var f = () => {
          super.g();
      };
      return (() => f());
    }

    g() {
        console.log('g');
    }
}

(new A().m())() // Expected console output: g

谢谢!

A 继承自 Object,而 Object.prototype 没有 g 方法。匿名函数与它没有任何关系。

您的意思是:

this.g();