Last active
October 6, 2015 18:54
-
-
Save karenpeng/f87448d9db6e1b4b459c to your computer and use it in GitHub Desktop.
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(){ | |
//console.log(i) | |
}, i * 1000) | |
} | |
for(var i = 0; i < 5; i++){ | |
(function(i){ | |
setTimeout(function(){ | |
console.log(i) | |
}, i * 1000)}(i)) | |
} | |
for(var i = 0; i < 5; i++){ | |
(function(i){ | |
setTimeout(function(){ | |
console.log(i) | |
}, i * 1000) | |
}.bind(this, i))() | |
} | |
for(var i = 0; i < 5; i++){ | |
setTimeout((function(i, j){ | |
return function(){ | |
console.log(i) | |
} | |
})(i, 0), i * 1000) | |
} | |
for (let i = 0; i < arr.length; i++) { | |
delayLog(i) | |
} | |
function delayLog(i) { | |
setTimeout(function () { | |
console.log(i) | |
}, i * 1000) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment