I was doing some code 10 times and then reinitializing the counter for the next use of the function. In the context of a DIV Element, my code was the following:
//Function to make DIV blink
this.blink = function() {
//Blink 10 times
this.times = (this.times-1)||10;
//If not 10 times yet
if ( this.times > 0 ) {
//Switch blink color
if ( this.times%2==0 )
this.style.backgroundColor = '#000';
else
this.style.backgroundColor = '#FFF';
this_ = this;
//Redo blink in 50 milliseconds
setTimeout('this_.blink()', 50);
else { //Times out, stop blinking, reset counter value
clearTimeout();
this.times = 10;
}
}
My point is on the very first line of the function:
this.times = (this.times-1)||10;
What it does is affecting 10 when this.times doesn't exist yet and then affects 9, 8, 7,...
But when it comes to 0, then the right operand choose 10 instead of 0 because 0 is considered as false. So it's going again and again without stopping from blinking!
I better stop at 1, which will work.