adequately good

decent programming advice

written by ben cherry



all articles filed under timers

Replacing `setTimeout` Globally

Sometimes, you might want to overwrite built-in global methods like setTimeout and setInterval. If you try, you might find that it's much harder than you think to accomplish this in every browser, particularly if you ever want to find the originals again. After a lot of painful experimentation, I think I have a definitive solution that works in all browsers with minimal side-effects.

Failed Approaches

I started ...

Minimum Timer Intervals in JavaScript

I was talking with a co-worker today about the behavior of setTimeout and setInterval when given a small interval, like 0 or 1. The expectation would be that the timer will fire in 0ms, or 1ms. However, as with other things in JavaScript, the reality is a bit different. It turns out that browsers actually have a minimum timer interval which they can't work any faster than ...