I am having a problem to stop the setTimeout function fired previously.
I found some relative questions and the giving solution is to put the time_out variable outside of the function to make it work. I tried but still not working.
this.A = function(){
if(time_out) clearTimeout(time_out);
// time_out is nothing here and this will return error
time_out = setTimeout(function(){ }, 3000);
}
-------------------------------------------------
this.time_out = 0;
this.A = function(){
if(this.time_out) clearTimeout(this.time_out);
//will run through, but the setTimeout setup previously will keep running...
this.time_out = setTimeout(function(){ }, 3000);
}
Update
I tired put the whole function into a element and call it out when reset
if(el.data('time_out')) clearTimeout(el.data('time_out'));
This works perfect
make sure you are in the proper scope.