I have the following function:
onDocumentKeyUp: function (e) {
if (e.keyCode === 27) {
this.deactivate();
}
}
I wanted to bind t
You can use .bind() to set the context (without immediately calling it like call
or apply
):
$(document).on('keyup', this.onDocumentKeyUp.bind(this));
As this method is only supported by ES5.1-compliant browsers, you might use jQuery.proxy instead of polyfilling it.
Draw your attention on data
parameter of the on
method here: http://api.jquery.com/on/
Also you can utilize jQuery.proxy method: http://api.jquery.com/jQuery.proxy/
Here is jsFiddle: jsFiddle