angular - 错误类型错误:无法读取未定义的属性“handleStopRecording”
问题描述
我正在调用 handleStopRecording() 函数,但出现错误 ERROR TypeError: Cannot read property 'handleStopRecording' of undefined
stream.getTracks().forEach(function (track) {
track.addEventListener(
"ended",
function () {
callback();
callback = function () {
console.log("stop recording")
this.handleStopRecording()
};
},
false
);
track.addEventListener(
"inactive",
function () {
callback();
callback = function () {
console.log("end");
};
},
false
);
});
}
解决方案
在您的情况下,查看this的上下文。在函数内部, this 的值取决于函数的调用方式。
您可以在以下位置获取更多信息:https ://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this
推荐阅读
- angular - 在ngForm中动态绑定名称属性?
- jenkins - 詹金斯日志解析器
- wpf - ScrollViewer 在 DockPanel 中不起作用
- java - 如何在二叉树中实现一种方法来返回变量后访问的下一个节点?
- java - 在 intellij 上使用 openjpa 进行手动动态增强
- react-admin - 使用 react-admin-s3-file-upload 反应管理员
- excel - Excel - 从行和列条件返回列引用
- c# - C# 如何使用 SkiaSharp 控件缩放到光标位置?
- php - 在php html中识别索引的问题
- python - 遍历子目录中的文件并加载它们