I wrote a class in javascript that looks like this:
function main()
{
this.var1 =0;
this.clock = function()
{
var t = this;
var n =1;
window.setInterval(document.write(this.n++),1000);
}
}
But after calling setInterval() ‘this’ refers to window. So i cannot access the variable inside the class. How can I solve this scope problem?
Notice that your code is wrapped in
function.