gpt4 book ai didi

javascript - 无法读取 undefined 的属性...,在 Object.callback 从 Native In angular 2

转载 作者:行者123 更新时间:2023-11-30 14:36:59 25 4
gpt4 key购买 nike

我有一个流程代码

declare var Speech: any;
export class Lesson implements OnInit {
text = '';
constructor()
{
this.text = 'hh';
}
ToSpeech(){
Speech.listen(this.listenSucess);
}
listenSucess(result){
this.text = reuslt;
}

文件 Speech.js

var Speech= (function () {
return {
listen:funtion(sucess){
window.plugins.speechRecognition.startListening(function (result) {
success(result);
}
}
}

我有一个错误:

Cannot read property 'this.text' of undefined 
at Object.callbackFromNative

我为这个函数使用了回调,谢谢。

最佳答案

您是否尝试使用粗箭头 => 而不是 function?因为 thisfunction

中不可访问
var Speech = (() => {
return {
listen = (success) => {
window.plugins.speechRecognition.startListening((result) => {
success(result);
}
}
}

关于javascript - 无法读取 undefined 的属性...,在 Object.callback 从 Native In angular 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50284598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com