6-async/02-promise-basics#186
Merged
leviding merged 10 commits intojavascript-tutorial:zh-hansfrom Aug 21, 2018
Starriers:translation/promise-basics
Merged
6-async/02-promise-basics#186leviding merged 10 commits intojavascript-tutorial:zh-hansfrom Starriers:translation/promise-basics
leviding merged 10 commits intojavascript-tutorial:zh-hansfrom
Starriers:translation/promise-basics
Conversation
|
校对认领 |
Contributor
Author
|
@caoyi0905 术语部分你可以看下 怎么翻译比较好 |
caoyi0905
reviewed
Aug 17, 2018
| 内置 `setTimeout` 函数会使用回调函数。创建一个基于 promise 的替代产物。 | ||
|
|
||
| The function `delay(ms)` should return a promise. That promise should resolve after `ms` milliseconds, so that we can add `.then` to it, like this: | ||
| `delay(ms)` 函数会返回 promise。这个 promise 应该在 `ms` 毫秒之后被处理。因此我们可以向它添加 `.then`,就像这样: |
| 想象一下,你自己是一位顶尖歌手,粉丝没日没夜地询问你下个单曲何时到来。 | ||
|
|
||
| To get a relief, you promise to send it to them when it's published. You give your fans a list. They can fill in their coordinates, so that when the song becomes available, all subscribed parties instantly get it. And if something goes very wrong, so that the song won't be published ever, then they are also to be notified. | ||
| 为了得到解脱,你承诺会在发行的第一时间让他们知道。你给了粉丝一张列表,他们可以填写自己的信息,因此它们会在歌曲发行的第一时间,所有订阅的人都可以立刻获知消息。如果发生了错误,也就是歌曲可能永远也不会被发行,他们也会被告知。 |
There was a problem hiding this comment.
整段翻译的有点僵硬。以下是我的翻译,供参考。
为了从中解放,你承诺会在单曲发布的第一时间通知他们。你让粉丝们填写了他们的个人信息,因此他们会在歌曲发布的第一时间获取到。即使遇到了不测,歌曲可能永远不会被发行,他们也会被通知到。
| 为了得到解脱,你承诺会在发行的第一时间让他们知道。你给了粉丝一张列表,他们可以填写自己的信息,因此它们会在歌曲发行的第一时间,所有订阅的人都可以立刻获知消息。如果发生了错误,也就是歌曲可能永远也不会被发行,他们也会被告知。 | ||
|
|
||
| Everyone is happy: you, because the people don't crowd you any more, and fans, because they won't miss the single. | ||
| 每个人都很开心:你,是因为没有人会再催促你,粉丝呢,则因为他们不会错误单曲发行的第一时间。 |
| 每个人都很开心:你,是因为没有人会再催促你,粉丝呢,则因为他们不会错误单曲发行的第一时间。 | ||
|
|
||
| That was a real-life analogy for things we often have in programming: | ||
| 在编程中,我们经常用现实世界中的事物进行类比: |
| 1. A "producing code" that does something and needs time. For instance, it loads a remote script. That's a "singer". | ||
| 2. A "consuming code" wants the result when it's ready. Many functions may need that result. These are "fans". | ||
| 3. A *promise* is a special JavaScript object that links them together. That's a "list". The producing code creates it and gives to everyone, so that they can subscribe for the result. | ||
| 1. "producing code" 会做一些事情,也需要事件。比如,它加载一个远程脚本。此时它就像“歌手”。 |
|
|
||
| ```smart header="Reject with `Error` objects" | ||
| Technically we can call `reject` (just like `resolve`) with any type of argument. But it's recommended to use `Error` objects in `reject` (or inherit from them). The reasoning for that will become obvious soon. | ||
| 从技术上来说,我们可以使用任何类型的参数来调用 `reject`(就像 `resolve`)。但建议在 `reject`(或从它们中继承)中使用 `Error` 对象。原因就会显示出来。 |
| ``` | ||
|
|
||
| The idea is that a job done by the executor may have only one result or an error. In programming, there exist other data structures that allow many "flowing" results, for instance streams and queues. They have their own advantages and disadvantages versus promises. They are not supported by JavaScript core and lack certain language features that promises provide, we don't cover them here to concentrate on promises. | ||
| 想法是,执行器所做的作业可能只有一个结果或者一个错误。在编程中,还有其他允许 "flowing" 结果的数据结构。例如流和队列。相对于 promise,它们有着自己的优势和劣势。它们不被 JavaScipt 核心支持,而且缺少 promise 所提供的某些语言特性,我们在这里不对 promise 进行过多的讨论。 |
| ``` | ||
|
|
||
| The call `.catch(f)` is a complete analog of `.then(null, f)`, it's just a shorthand. | ||
| 调用 `.catch(f)` 是 `.then(null, f)` 的模拟,它只做快速记录。 |
| promise.then(alert); // 完成!(在当前代码完成之后) | ||
|
|
||
| alert("code finished"); // this alert shows first | ||
| alert("code finished"); // 这个报警会最先显示 |
Contributor
Author
There was a problem hiding this comment.
这个 问题 不知道怎么解决 。因为有的人翻译,有的人不翻译。
| ``` | ||
|
|
||
| Usage: | ||
| 使用: |
Member
Member
|
@Starriers 修改下吧 |
Contributor
Author
|
Modify : |
Contributor
Author
|
@caoyi0905 @leviding Proofreading modification have been done! |
Member
|
@Starriers 可以建一个 glossary 放进去? |
Member
|
@Starriers 建好了,在 WIKI |
Contributor
Author
|
@leviding 那是啥 |
Member
|
@Starriers 术语表 |
leviding
approved these changes
Aug 21, 2018
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To 校对人员: callback 最后再统一改为 回调函数 现在不想修改了