我有以下代码,我试图在swipe事件中调用触发任何功能的this.swipe方法。问题是,在this.carousel.swipe上下文中它不知道this.swipe是什么。如何触发此功能?
PM.SwipeCarousel = function (carouselSelector) {
this.carousel = $j(carouselSelector);
this.carousel.swipe({
swipe : this.swipe
})
// method to call
this.swipe = function(event, direction, distance, duration, fingerCount, fingerData) {
console.log(event, direction, distance, duration, fingerCount, fingerData);
}
}
最佳答案
如建议的代码应该是
PM.SwipeCarousel = function (carouselSelector) {
this.carousel = $j(carouselSelector);
// method to call
this.swipe = function(event, direction, distance, duration, fingerCount, fingerData) {
console.log(event, direction, distance, duration, fingerCount, fingerData);
}
this.carousel.swipe({
swipe : this.swipe
})
}