ES6jQuery将侦听器绑定为匿名函数



我想将一个匿名函数绑定到ES6类中的jQuery事件侦听器。

类似于:

class MyClass{    
constructor(){
$( document ).mousedown( callAnonymous );
}    
callAnonymous(e){
//Need class references here
}
}

这有一个简单的语法吗?在网上找不到任何内容。

您可以像绑定任何正常函数一样绑定它:

$(document).mousedown(this.callAnonymous.bind(this));

最新更新