When I try access to the object with "this" keyword, I am getting the "window" object instead of object's itself because I bind it's function to an event and that event belongs to window object.
In the example, alert(this.osd)
says that it is undefined because there is no "osd" in the "window" object. So, what is the best way to solve this ? Defining the game object as window.game ?
var game = {
osd : null,
stage : null,
tick : function(){
alert(this.osd);
},
init : function(){
// Configure the OSD
this.osd = "a";
// Preapare the stage;
this.stage = "b";
window.addEventListener("click",this.tick);
}
}
game.init();