我想从audio.onerror函数访问isDisabled变量,并希望重置isDisabled的值,但无法设置它。
public isDisabled: boolean = false;
private verifyPrompt(url: string): boolean{
let audio = new Audio(this.promptMessageUrl);
this.isDisabled =
audio.load;
audio.onerror = function(e){
this.isDisabled = true;
}
}
答案 0 :(得分:0)
删除function
关键字并使用箭头函数表示法()=>
。
audio.onerror = (e) => {
this.isDisabled = true;
}