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

如何让 JavaScript 中的循环慢下来 #7919

Merged
merged 4 commits into from
Feb 2, 2021
Merged

如何让 JavaScript 中的循环慢下来 #7919

merged 4 commits into from
Feb 2, 2021

Conversation

PassionPenguin
Copy link
Contributor

译文翻译完成,resolve #7913 @lsvih

Copy link
Contributor Author

@PassionPenguin PassionPenguin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes

article/2021/how-to-slow-down-a-for-loop-in-javascript.md Outdated Show resolved Hide resolved
article/2021/how-to-slow-down-a-for-loop-in-javascript.md Outdated Show resolved Hide resolved
article/2021/how-to-slow-down-a-for-loop-in-javascript.md Outdated Show resolved Hide resolved
@PassionPenguin PassionPenguin marked this pull request as ready for review January 25, 2021 17:08
@cool-summer-021
Copy link
Contributor

@lsvih 校对认领

@lsvih
Copy link
Member

lsvih commented Jan 26, 2021

@SamYu2000 欢迎校对~

@Usualminds
Copy link
Contributor

@lsvih 校对认领

@lsvih
Copy link
Member

lsvih commented Jan 26, 2021

@Usualminds 好的~

Copy link
Contributor

@Usualminds Usualminds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lsvih @PassionPenguin 校对完成,提了几个小建议

article/2021/how-to-slow-down-a-for-loop-in-javascript.md Outdated Show resolved Hide resolved
article/2021/how-to-slow-down-a-for-loop-in-javascript.md Outdated Show resolved Hide resolved
article/2021/how-to-slow-down-a-for-loop-in-javascript.md Outdated Show resolved Hide resolved
article/2021/how-to-slow-down-a-for-loop-in-javascript.md Outdated Show resolved Hide resolved
article/2021/how-to-slow-down-a-for-loop-in-javascript.md Outdated Show resolved Hide resolved
article/2021/how-to-slow-down-a-for-loop-in-javascript.md Outdated Show resolved Hide resolved
article/2021/how-to-slow-down-a-for-loop-in-javascript.md Outdated Show resolved Hide resolved

So with a **setTimeout**, it does not work as it should.
因此,如果我们使用 **setTimeout**,它将无法达到我们的预期。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因此 => 既然

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里还是因此比较好,既然的话就需要把下一句话合并上来,不然就没有转折是病句了

article/2021/how-to-slow-down-a-for-loop-in-javascript.md Outdated Show resolved Hide resolved
Copy link
Contributor

@cool-summer-021 cool-summer-021 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PassionPenguin @lsvih 校对完成

article/2021/how-to-slow-down-a-for-loop-in-javascript.md Outdated Show resolved Hide resolved
article/2021/how-to-slow-down-a-for-loop-in-javascript.md Outdated Show resolved Hide resolved

## First — how it does not work
## 首先:不起作用的方法
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

首先需要指出:下面的方法是不起作用的

Copy link
Contributor Author

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 嗷

article/2021/how-to-slow-down-a-for-loop-in-javascript.md Outdated Show resolved Hide resolved
article/2021/how-to-slow-down-a-for-loop-in-javascript.md Outdated Show resolved Hide resolved
article/2021/how-to-slow-down-a-for-loop-in-javascript.md Outdated Show resolved Hide resolved
}

doSomething()
```
程序每秒执行一次日志打印操作。因此,要输出循环的所有数字,我们需要等待 100 秒 —— 我们已成功放缓了 For 循环的执行速度。
Copy link
Contributor

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 的知识,请看一下这部分内容。
Copy link
Contributor

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 秒钟内没有任何反应,随后所有日志同时被打印在控制台上。
Copy link
Contributor

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 循环中:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Promise 足以实现我们的预期 => 使用 Promise 可以实现我们需要的功能

@PassionPenguin
Copy link
Contributor Author

嗷没留意到,稍等 @SamYu2000

Co-authored-by: zenblo <[email protected]>
Co-authored-by: samyu2000 <[email protected]>
@PassionPenguin
Copy link
Contributor Author

PassionPenguin commented Feb 2, 2021

@SamYu2000 @Usualminds 校对完成啦,有部分内容没有更改,没有必要,然后部分内容合并了两个校对意见

@lsvih lsvih merged commit 51fb764 into xitu:master Feb 2, 2021
@lsvih
Copy link
Member

lsvih commented Feb 2, 2021

@PassionPenguin 已经 merge 啦~ 快快麻溜发布到掘金然后给我发下链接,方便及时添加积分哟。

掘金翻译计划有自己的知乎专栏,你也可以投稿哈,推荐使用一个好用的插件
专栏地址:https://zhuanlan.zhihu.com/juejinfanyi

@PassionPenguin PassionPenguin deleted the translation/how-to-slow-down-a-for-loop-in-javascript branch February 2, 2021 04:04
@PassionPenguin
Copy link
Contributor Author

PassionPenguin commented Feb 2, 2021

@Usualminds
Copy link
Contributor

@PassionPenguin 校对者加下我,你好像添加错人了,哈哈

@PassionPenguin
Copy link
Contributor Author

诶抱歉抱歉

@PassionPenguin
Copy link
Contributor Author

Fixed:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

如何让 JavaScript 中的循环慢下来
4 participants