Last active
October 9, 2018 11:58
-
-
Save onurkerimov/1c69bdbd33890a5b1e5ffbea7e6b4142 to your computer and use it in GitHub Desktop.
A practical setInterval function wrapper that I oftenly use, in which the interval is cleared when the callback function returns true.
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
(function() { | |
$.setInterval = function(int, fn) { | |
var returnValue | |
var interval = setInterval(function() { | |
if (returnValue === true) { | |
clearInterval(interval); | |
} else { | |
returnValue = fn() | |
} | |
}, int) | |
return interval | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of the following routine:
easily:
Pros: