mrchimp / tock

Timer Object/Class. Kickass!
MIT License
237 stars 33 forks source link

Fix stop/reset bug when there are multiple instances of a timer on the same page. #5

Closed kara-todd closed 10 years ago

kara-todd commented 10 years ago

I ran into a problem where if you call reset() or stop() with multiple timers running it will actually stop all of them. :)

This is because the setTimeout ID returns just an incremented number. After the first timeout was stopped it would then stop the second occurrence of the timer. To solve this issue I added a prefix which adds a unique id to each timer instance.

I was also having issues with clicking "reset" borking the time of the other timers. Adding start_time, time, and elapsed as private variables seemed to fix this issue. I don't think it broke anything. ;)

mrchimp commented 10 years ago

Looks good to me. Thanks!