A better setInterval for Javascript

Gustavo Paes

Publicado em:

Compartilhe:
var runs = 1;
function yourActionFunction() {
    var log = document.getElementById("log");
    log.innerHTML += runs+". running again!
"; return runs++ < 5; } /** This is a new setInterval function */ (function(time) { function again() { var procede = yourActionFunction(); if(procede) setTimeout(again, time); } again(time); })(5000);

Contribute: https://gist.github.com/984668