diff --git a/api/throttle.js b/api/throttle.js index cd4f4470..7cb4b2d7 100644 --- a/api/throttle.js +++ b/api/throttle.js @@ -1,12 +1,16 @@ "use strict" +var ts = Date.now || function() { + return new Date().getTime() +} + module.exports = function(callback) { //60fps translates to 16.6ms, round it down since setTimeout requires int var time = 16 var last = 0, pending = null var timeout = typeof requestAnimationFrame === "function" ? requestAnimationFrame : setTimeout return function(synchronous) { - var now = new Date().getTime() + var now = ts() if (synchronous === true || last === 0 || now - last >= time) { last = now callback() @@ -15,7 +19,7 @@ module.exports = function(callback) { pending = timeout(function() { pending = null callback() - last = new Date().getTime() + last = ts() }, time - (now - last)) } }