2016-09-06 22 views
1

我有下面的代碼,我試圖在刷卡事件中調用this.swipe它觸發任何函數的方法。問題是它不知道這是什麼.swipe在上下文this.carousel.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); 
    } 

} 
+5

你試圖通過該方法已創建它。 – Bergi

回答

0

至於建議的代碼應該已經

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 
}) 

}

相關問題