Last active
August 29, 2015 14:20
-
-
Save sagiavinash/018c66d7fd34312a555c to your computer and use it in GitHub Desktop.
Immediately invoked setInterval
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
/* Instead of | |
interval(); | |
setInterval(interval, 1000); | |
*/ | |
// -1. Invocation function already defined. | |
// Never use this even if it looks awesome implicit eval is slow because of an additional parse step. | |
function interval(){ | |
console.log("Invoked"); | |
} | |
setInterval("interval()", 1000); | |
// 1. Invocation function already defined. | |
function interval(){ | |
console.log("Invoked"); | |
} | |
setInterval((interval() || interval), 1000); //as setInterval fn's are not mearnt to return. interval() always evaluates to undefined. | |
// 2. Invocation function declared there itself. | |
setInterval((function interval() { | |
console.log("Invoked"); | |
return interval; | |
})(), 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment