如何调用此事件内部的函数?
myfunction() {
alert('bla bla!');
}
this.map.on('moveend', function() {
console.log('moveend :: ' + this.getCenter());
this.myfunction(); // => ERROR TypeError: this.myfunction is not a function
});
最佳答案
尝试以下操作
this.map.on('moveend', () => {
console.log('moveend :: ' + this.getCenter());
this.myfunction();
});
这应该有效。
注意:您遇到的问题是scope 。我建议阅读一些内容,这是一个值得理解的概念。
关于javascript - 如何使用 "this"调用事件内的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61013732/