javascript - 为什么这个构造方法无效?
问题描述
为什么这会给我一个错误:“未捕获的 TypeError:Parent.child 不是函数”
function Parent () {
this.child = (num) => {
console.log(num);
}
}
Parent.child(4);
解决方案
试试这个方法
function Parent () {
this.child = (num) => {
console.log(num);
}
}
const p = new Parent();
p.child(4);
推荐阅读
- python - 我试图以 100hz 采样,而不是像程序运行一样快。我该怎么做?
- django - 如何从 Django 模型表单中的 POST 请求中提取单个值?
- python - 如何根据时间不在列表中的时间戳删除行
- cron - Cron schedule to run at 11:55, 12:00 and 12:05
- angular - 在Angular 6中只允许只有一位小数的正数
- python - 在 Python 中的任何文件或目录中重命名部分名称
- zooming - 如何调整打开图层的缩放以查看地图上的所有 POI 和标记
- c# - 极其简单的线性搜索不适用于 Android 和 iOS
- vuejs2 - 在组件属性中使用 Lang.js
- elasticsearch - 限制聚合处理的结果数量