Last active
February 11, 2018 12:52
-
-
Save jessepollak/7762987 to your computer and use it in GitHub Desktop.
setInterval + Immediately Invoked Function Expressions == instaInterval.
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
setInterval((function interval() { | |
// do something instantly then every 5 seconds | |
console.log('This is a better version of setInterval'); | |
return interval; | |
})(), 5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Clever solution. I'm in a weirdo-javascript-hacky mood this evening, so I have two enhancements I want on this code:
return interval;
puking out memory forever. It's nit-picky, but why not?Here's the gross one-liner:
And the cleaner function version:
Both can be executed at any time to kick off the interval:
interval();