let's say I have a JavaScript-Class like this:
Foo.prototype = {
init: function() {
$(document).keydown(function(event) {
this.onKeyDown(event);
});
}
onKeyDown: function(event) {
alert("bar");
}
}
myObj = new Foo();
myObj.init();
This Code won't work, because in
$(document).keydown(function(event) {
this.onKeyDown(event);
});
the 'this' is of course unknown and doesn't address the object. How can i address the onkeydown-method of the Foo-Class anyhow?
I don't want exchange 'this' with 'myObj' (the name of the Object) since i may want to use the class for other Objects aswell.
Thanks for your help!