class SwipeController {
constructor(threshold) {
var myElement = document.getElementById('swipecontainer');
myElement.width = $( window ).width();
myElement.height = $( window ).height();
var mc = new Hammer(myElement);
mc.get('pan').set({ direction: Hammer.DIRECTION_ALL, threshold: threshold });
this.swiperight = new Array();
this.swipeleft = new Array();
mc.on("panright", function(ev) {
alert(this.swiperight)
this.swiperight.forEach(function(func) {
func();
})
});
mc.on("panleft", function(ev) {
this.swipeleft.forEach(function(func) {
func();
})
});
}
set swipeRight(value) {
this.swiperight.push(value)
}
set swipeLeft(value) {
this.swipeleft.push(value)
}
}
module.exports = SwipeController;
I realize that alert(this.swiperight) is showing as undefined because "this" is no longer the SwipeController class. How do I go about doing this? I'm trying to make this event trigger to trigger ANY event i connect to it, so I can handle all my swipe detection from one class.