Last active
March 3, 2016 06:07
-
-
Save black-black-cat/f49b2d553484c84d00e5 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 d = 0; d < 3; d++ ) { | |
// 定时器异步执行,它执行时循环已经结束,d的值为3 | |
setTimeout(function(){ | |
console.log(d); | |
}, 100); | |
// console记录3次 | |
// -> 3 | |
// -> 3 | |
// -> 3 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment