Created
May 3, 2014 03:47
-
-
Save larruda/ae1570fa51c997cc4a3f to your computer and use it in GitHub Desktop.
Alternative to JavaScript's setInterval by http://www.thecodeship.com/web-development/alternative-to-javascript-evil-setinterval/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function interval(func, wait, times){ | |
var interv = function(w, t){ | |
return function(){ | |
if(typeof t === "undefined" || t-- > 0){ | |
setTimeout(interv, w); | |
try{ | |
func.call(null); | |
} | |
catch(e){ | |
t = 0; | |
throw e.toString(); | |
} | |
} | |
}; | |
}(wait, times); | |
setTimeout(interv, wait); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment