We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
for (var i = 0; i < 5; i++) { setTimeout(() => { console.log(i) }, 1000) }
请问上面的代码如何输出?
上面的代码一秒之后一次性输出55555
55555
问题1:如何一次性输出0, 1, 2, 3, 4?
0, 1, 2, 3, 4
for (let i = 0; i < 5; i++) { setTimeout(() => { console.log(i) }, 1000) }
for (var i = 0; i < 5; i++) { ((i) => { setTimeout(() => { console.log(i) },1000) })(i) }
问题2:如何每隔一秒输出i
for (let i = 0; i < 5; i++) { setTimeout(() => { console.log(i) }, 1000 * (i + 1)) } for (var i = 0; i < 5; i++) { ((i) => { setTimeout(() => { console.log(i) },1000 * (i + 1)) })(i) }
使用async
(async () => { for (let i = 0; i < 5; i++) { await new Promise(resolve => { setTimeout(resolve, 1000) }) console.log(i) } })()
使用promise
The text was updated successfully, but these errors were encountered:
No branches or pull requests
请问上面的代码如何输出?
上面的代码一秒之后一次性输出
55555
问题1:如何一次性输出
0, 1, 2, 3, 4
?问题2:如何每隔一秒输出i
使用async
使用promise
The text was updated successfully, but these errors were encountered: