Here is my code:
var timer =
{
i: "Hello",
start: function()
{
var self = this;
window.setInterval(self.tick, 1000);
},
tick: function()
{
console.log(this.i);
}
}
timer.start();
Why the javascript console displays undefined?
thisin JavaScript works differently than in most other languages. See stackoverflow.com/questions/15858507/javascript-binding-issue .