0

i want to bind an anonymous function to a jQuery event listener inside an ES6 class.

Something like:

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

Is there a simple syntax for this? Couldn't find anything on the web.

DeadApe
  • 416
  • 1
  • 3
  • 10

1 Answers1

0

You would bind it like you would any normal function:

$(document).mousedown(this.callAnonymous.bind(this));
Aplet123
  • 33,825
  • 1
  • 29
  • 55