I have a simple js structure like this :
var Waiting = (function () {
function Waiting() {
this.timer;
}
Waiting.prototype.show = function () {
var self = this;
clearTimeout( self.timer );
self.timer = setTimeout( function(){ self.hideLogo(); },3000);
}
Waiting.prototype.hideLogo = function () {
console.log("ok i passed timeout");
};
return Waiting;
})();
As expected, I get the “ok i passed timeout” log on every browser the first time I execute the show function (which called the hideLogo one). The problem appears in IE9 when I called for the second time the show function. This time, the hideLogo function is never called (log never appears in IE console). I tried a lot of things without any success.
If anyone as an idea…
When you’re using
setTimeout, the function that is being called looses the context: in other wordsthisdoesn’t post to the instance on which the method is called anymore. You’re usingselfto cancel this issue out, butselfis, itself, an iffy word (as in reserved keyword). Perhaps usethat, and use an IIFE in thesetTimeoutcall:At first glance, that’s the only thing I can see that might be the issue with your code: the
clearTimeoutcall shouldn’t be an issue, but I like to call it at the end of the timeout itself, and theselfambiguity thing. Let me know if this changes anything for you!