Firefox invokes setTimeout function too soon (or Date.getTime() is off?)
<p>I've run into a strange issue in Firefox 12. setTimeout() doesn't seem to always wait the appropriate length. Or perhaps it's the date's milliseconds that don't jive?</p>

<p><a href="http://jsfiddle.net/katowulf/C6pZX/3/" rel="nofollow">Check out this fiddle.</a> Essentially, a setTimeout of 100ms seems to run anywhere between 80ms and 110ms. More I can understand, based on <a href="http://ejohn.org/blog/how-javascript-timers-work/" rel="nofollow">John Resig's explanation of timers</a>. But less?</p>

<p>You may have to refresh it once or twice to see the issue, as it sometimes works correctly on the first run. It seems to work spifftacular in IE and Chrome.</p>

<p>Here's the code I'm using in my fiddle:</p>

<pre><code>var txt = '',
    TIMEOUT_LENGTH = 100,
    _now;

now = Date.now || function() { return new Date().getTime() };

function log(time) {
    c = time &lt; 100? 'class="error"' : '';
    $('#log').append('&lt;p '+c+'&gt;waited ' + time + '&lt;/p&gt;');
}

function defer() {
    var d = $.Deferred(),
        start = now();
    setTimeout(function() {
        d.resolve(now() - start);
    }, TIMEOUT_LENGTH);
    return d.promise();
}

for (var i = 0; i &lt; 20; i++) {
    defer().then(log);
}
</code></pre>

<p>Here's a sample of the quirky output:</p>

<p><img src="http://i.stack.imgur.com/lYiYg.png" alt="enter image description here"></p>

<p>Here's my browser info:</p>

<p><img src="http://i.stack.imgur.com/iPr0I.png" alt="enter image description here"></p>

<p>And thanks so much for reading my question! I hope someone can shed some light into this.</p>

<p><strong>MORE INFO</strong></p>

<p>I worked around the problem by using setInterval() and checking each increment to see if the required time has passed. <a href="http://jsfiddle.net/katowulf/C6pZX/5/" rel="nofollow">See this fiddle</a>.</p>

<p>However, I'm still very interested to hear if anyone can shed some light into the source of the issue</p>
