I am a C# developer experimenting with JavaScript and I\'m trying to get my head around the scope :)
I have the following code which contains an addEventListe
Keyboard.prototype.listen = function() {
var self = this;
window.addEventListener('keydown', function(event) {
self.handle_keydown(event);
// self is your Keyboard object. You can refer to all your properties from this
});
}
How this code works:
this variable. this points to the dom object, while self points to keyboard object.event as a parameter that we pass on to the member function of the keyboard object.