unshiftio / tick-tock

Timer management, never forget to clear timers again.
http://unshift.io
MIT License
17 stars 8 forks source link

fix "Illegal invocation" error in Chrome #2

Closed xadn closed 9 years ago

xadn commented 9 years ago

I noticed this while trying Liferaft in the browser. Calling clearTimeout like timer.clear changes the binding of this and causes an error in Chrome, but I'm not sure why or if this happens in other browsers. Binding clearTimeout to null seems to fix it.

Note: this fails the code coverage precommit hook, not sure how to best test this with the current mocha setup.

3rd-Eden commented 9 years ago

I want to make sure that this module stays ES3 compatible so I think the best way would be just wrap clearTimeout in a function:

tick.timers[name] = {
     timer: setInterval(tick.tock(name), ms(time)),
     clear: function clear(what) { clearInterval(what); }
     fns: [fn]
   };

But we probably have to do that for every setup.

coveralls commented 9 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 19651583b93e936241a564e875f92d16a7d5c1d4 on xadn:master into 93b5adc1171cee17b2d7c3b5d2e916baf45f4525 on unshiftio:master.

coveralls commented 9 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling e1dba13bd439efdf1c8013ea71fb8c07a041543d on xadn:master into 93b5adc1171cee17b2d7c3b5d2e916baf45f4525 on unshiftio:master.

3rd-Eden commented 9 years ago

Awesome, thanks the pull request and processing the changes. I'll publish a new version in a bit.