2017-01-15 9 views
0

ので、私は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 
    } 

} 

グローバル変数を使用せずに現在のオブジェクトを呼び出すの何らかの方法があるの?

答えて

1
あなたは "自己" を宣言ハンドラに移動し

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 
    } 

} 
+0

おかげでシンプルなソリューションを –

関連する問題