core.js:6241 ERROR TypeError: this.test is not a function at klass.<anonymous> 嘗試在畫布中呼叫函式時出錯
HTML
<canvas #canvas id="canvas" width="900" height="400"></canvas>
ts
ngOnInit() {
this.cvs.on("stagemouse:down", function(){
console.log('Event mouse:down Triggered');
this.test();
})
}
test(){
console.log("test");
}
uj5u.com熱心網友回復:
使用 定義函式時function(),它不是“系結”的,這意味著 的值this可能并不總是相同,具體取決于函式被呼叫的時間和地點。要宣告“系結”函式,請使用箭頭語法:
this.cvs.on("stagemouse:down", () => {
console.log('Event mouse:down Triggered');
this.test();
});
此語法使this函式中始終參考this創建時當前存在的 。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/394479.html
下一篇:ngFor只點擊一項
