首页 > 解决方案 > JS(中间值).g 不是函数 使用超级运算符时中间值不是函数

问题描述

我试图从 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

谢谢!

标签: javascriptclasssuper

解决方案


A扩展自Object,并且Object.prototype没有g方法。匿名函数与它没有任何关系。

你的意思:

this.g();

推荐阅读