-
Notifications
You must be signed in to change notification settings - Fork 5k
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
如何让 JavaScript 中的循环慢下来 #7919
如何让 JavaScript 中的循环慢下来 #7919
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor changes
@lsvih 校对认领 |
@SamYu2000 欢迎校对~ |
@lsvih 校对认领 |
@Usualminds 好的~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lsvih @PassionPenguin 校对完成,提了几个小建议
|
||
So with a **setTimeout**, it does not work as it should. | ||
因此,如果我们使用 **setTimeout**,它将无法达到我们的预期。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
因此 => 既然
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里还是因此比较好,既然的话就需要把下一句话合并上来,不然就没有转折是病句了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PassionPenguin @lsvih 校对完成
|
||
## First — how it does not work | ||
## 首先:不起作用的方法 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
首先需要指出:下面的方法是不起作用的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不是吧,how
it doesnt work 强调 how 嗷
} | ||
|
||
doSomething() | ||
``` | ||
程序每秒执行一次日志打印操作。因此,要输出循环的所有数字,我们需要等待 100 秒 —— 我们已成功放缓了 For 循环的执行速度。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们已成功放缓了 For 循环的执行速度 => 我们已经实现了放慢 For 循环执行速度这一目的。
|
||
If you’re looking for a direct solution to your problem, feel free to skip this part. If you want to learn something about JS, then stay for a moment. | ||
I want to explain why common solutions don’t work. | ||
如果您正在寻找直接解决问题的方法,请随时跳过此部分。如果您想学习有关 JavaScript 的知识,请看一下这部分内容。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请随时跳过此部分 => 请跳过这部分。
nothing happens for 1 second; then all the logs come up in a flash. | ||
Not really what we had hoped for. | ||
当我们使用 **`setTimeout`** 运行代码时,会发生以下情况: | ||
* 在开始的 1 秒钟内没有任何反应,随后所有日志同时被打印在控制台上。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
随后所有日志同时被打印在控制台上 => 然后控制台上很快显示了所有日志。
} | ||
``` | ||
|
||
The Promise is ready. Now we can add it to our for-loop: | ||
也就是说,Promise 足以实现我们的预期。现在让我们将它添加到 For 循环中: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Promise 足以实现我们的预期 => 使用 Promise 可以实现我们需要的功能
嗷没留意到,稍等 @SamYu2000 |
Co-authored-by: zenblo <[email protected]> Co-authored-by: samyu2000 <[email protected]>
@SamYu2000 @Usualminds 校对完成啦,有部分内容没有更改,没有必要,然后部分内容合并了两个校对意见 |
@PassionPenguin 已经 merge 啦~ 快快麻溜发布到掘金然后给我发下链接,方便及时添加积分哟。 掘金翻译计划有自己的知乎专栏,你也可以投稿哈,推荐使用一个好用的插件。 |
@PassionPenguin 校对者加下我,你好像添加错人了,哈哈 |
诶抱歉抱歉 |
Fixed:) |
译文翻译完成,resolve #7913 @lsvih