Skip to content

Instantly share code, notes, and snippets.

@black-black-cat
Last active March 3, 2016 06:07
Show Gist options
  • Save black-black-cat/f49b2d553484c84d00e5 to your computer and use it in GitHub Desktop.
Save black-black-cat/f49b2d553484c84d00e5 to your computer and use it in GitHub Desktop.
定时器与闭包
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