所以我开始使用interactjs 我有这个简单的代码:
class example {
registerTouchEvents() {
var self = this;
interact('.touchy').draggable({
onstart: self.onStart,
});
}
onStart(event) {
this.someAction();//<-- not working as this is interact object
}
someAction() {
console.log('touch has been started') //<-- I need to call this function
}
}
有没有办法在不使用全局变量的情况下调用当前对象?
最佳答案
将处理程序移动到声明“self”的位置:
class example {
registerTouchEvents() {
var self = this
, onStart = function onStart(event) {
self .someAction();
}
;
interact('.touchy').draggable({
onstart: onStart,
});
}
someAction() {
console.log('touch has been started') //<-- I need to call this function
}
}
关于javascript - 如何使用更改默认 this 的库来调用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41659542/