Last active
March 13, 2017 13:31
-
-
Save DannyDelott/56d605d5870dede6663f to your computer and use it in GitHub Desktop.
Use a recursive setTimeout instead of setInterval
This file contains 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
var betterInterval = function(execute, delay, reverse) { | |
execute.stop = false; | |
execute.stopped = false; | |
if(reverse){ execute(); } | |
(function subroutine() { | |
setTimeout(function() { | |
if(!execute.stop){ | |
execute(); | |
subroutine(); | |
}else{ execute.stopped = true; } | |
}, delay); | |
})(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment