Skip to content

Instantly share code, notes, and snippets.

@patelprashant
Created November 18, 2013 04:18
Show Gist options
  • Select an option

  • Save patelprashant/7522400 to your computer and use it in GitHub Desktop.

Select an option

Save patelprashant/7522400 to your computer and use it in GitHub Desktop.
Set Interval function in javascript
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);
};
//usage
interval(function(){
// Code block goes here
}, 1000, 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment