Created
June 7, 2017 18:33
-
-
Save hoffination/489bc1d9161961206b5cf40b633d07d4 to your computer and use it in GitHub Desktop.
Example of how to use bind to save off variables for the callback within a setTimeout
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
for(var i = 0; i < 5; i++) { | |
setTimeout(function(printMe) { | |
console.log(printMe); | |
}.bind(null, i), i * 1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment