Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue#166 #170

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion JS/JS-ch.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ for ( var i=1; i<=5; i++) {
}
```

首先因为 `setTimeout` 是个异步函数,所有会先把循环全部执行完毕,这时候 `i` 就是 6 了,所以会输出一堆 6。
首先因为 `setTimeout` 是个异步函数,所以会先把循环全部执行完毕,这时候 `i` 就是 6 了,所以会输出5个 6。

解决办法两种,第一种使用闭包

Expand Down