javascript - 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
谢谢!
解决方案
A
扩展自Object
,并且Object.prototype
没有g
方法。匿名函数与它没有任何关系。
你的意思:
this.g();
推荐阅读
- json - Json 到 CSV 问题
- unix - 如何在 zip (Linux) 中获取文件名和总数
- node.js - Bot框架(nodejs v4)在Fb消息上的提示位置
- javascript - 是的,如何验证空对象上的必填字段
- db2 - DB2:需要提取分隔符左侧的字符串
- reactjs - 无法从 npm 安装 reactstrap
- windows-installer - 使用 NSIS 安装在 ProgramData 文件夹中
- tensorflow - TensorFlow v1 和 v2 中 Keras 的 ZeroPadding2D 的区别?
- authentication - cakephp 4 - 烘焙新控制器时找不到身份验证组件
- r - 可分配性图 - 绘制属于三个组的概率