Skip to content

Instantly share code, notes, and snippets.

@xperiments
Last active February 13, 2018 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xperiments/7693698 to your computer and use it in GitHub Desktop.
Save xperiments/7693698 to your computer and use it in GitHub Desktop.
[[js][hacks]] Better setInterval #js #hacks #tips
// http://www.thecodeship.com/web-development/alternative-to-javascript-evil-setinterval/
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