Created
December 11, 2013 08:03
-
-
Save angusjune/7906635 to your computer and use it in GitHub Desktop.
Javascript functions
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
//a alternative to javascript 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); | |
}; | |
//call function | |
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