As we know , setTimeout
is not working correctly with this
becuase it runs in a global scope ( and this
will be window
)
But I've made a simple test :
Just wrap it with function :
var o={}
o.a=1;
o.m=function (){alert(this.a);}
setTimeout(
function (){
o.m() ;
}
,100);
And it does alert 1
.
Am I missing something here ? why none of the answer suggests this solution ? does it behave different ?
p.s. : for those who intereseted here is a demo where it fails :
var o={}
o.a=1;
o.m=function (){alert(this.a);}
setTimeout( o.m ,100); //undefined