6-async/01-callbacks#185
Merged
leviding merged 6 commits intojavascript-tutorial:zh-hansfrom Aug 21, 2018
Starriers:translation/animate-circle-callback
Merged
6-async/01-callbacks#185leviding merged 6 commits intojavascript-tutorial:zh-hansfrom Starriers:translation/animate-circle-callback
leviding merged 6 commits intojavascript-tutorial:zh-hansfrom
Starriers:translation/animate-circle-callback
Conversation
Contributor
|
校对认领 |
upupming
reviewed
Aug 18, 2018
| 函数是**异步**调用的,因为动作不是此刻(加载脚本)完成的,而是之后。 | ||
|
|
||
| The call initiates the script loading, then the execution continues. While the script is loading, the code below may finish executing, and if the loading takes time, other scripts may run meanwhile too. | ||
| 调用开始于脚本加载,然后继续执行。当脚本正在被加载时,下面的代码可能已经完成了执行,如果加载需要时间,那么同一时间,其他脚本就会被运行。 |
Contributor
There was a problem hiding this comment.
initiates 应为『启动』、『初始化』
『就会』->『可能也会』
| ``` | ||
|
|
||
| Now let's say we want to use the new script when it loads. It probably declares new functions, so we'd like to run them. | ||
| 现在,我们假设在新脚本被加载完成时,被立即使用。它可能声明了新函数,因此我们想要运行它们。 |
| 现在,我们假设在新脚本被加载完成时,被立即使用。它可能声明了新函数,因此我们想要运行它们。 | ||
|
|
||
| But if we do that immediately after the `loadScript(…)` call, that wouldn't work: | ||
| 但如果我们在 `loadScript(…)` 调用时,立即那么做,就会导致操作失败。 |
|
|
||
| ```js | ||
| loadScript('/my/script.js'); // the script has "function newFunction() {…}" | ||
| loadScript('/my/script.js'); // 脚本还有 "function newFunction() {…}" |
Contributor
There was a problem hiding this comment.
作者的本意是脚本内部定义了这个函数,『还有』->『含有』
| ``` | ||
|
|
||
| Naturally, the browser probably didn't have time to load the script. So the immediate call to the new function fails. As of now, `loadScript` function doesn't provide a way to track the load completion. The script loads and eventually runs, that's all. But we'd like to know when it happens, to use new functions and variables from that script. | ||
| 很明显,浏览器没有时间去加载脚本。因此,对新函数的立即调用失败了。`loadScript` 函数并没有提供追踪加载完成时方法。脚本加载然后最终的运行,仅此而已。但我们希望通过脚本中的新函数以及变量,了解它发生的时间。 |
Contributor
There was a problem hiding this comment.
脚本加载然后最终的运行
『但我们希望通过脚本中的新函数以及变量,了解它发生的时间。』理解有些微偏差『但我们希望了解脚本何时加载完成,以使用其中的新函数和新变量』
| 看到了么?效果一样,但是没有深层的嵌套了,因为我们使每个动作都有一个独立的顶层函数。 | ||
|
|
||
| It works, but the code looks like a torn apart spreadsheet. It's difficult to read, you probably noticed that. One needs to eye-jump between pieces while reading it. That's inconvenient, especially the reader is not familiar with the code and doesn't know where to eye-jump. | ||
| 这很有效,但代码看起来就像是一个被撕开的表格。你可能注意到了,它的可读性非常差。在阅读时,需要在块之间切换。这非常不方便,尤其是不熟悉代码的读者,他们甚至不知道代码间如果跳转。 |
Contributor
There was a problem hiding this comment.
『撕开』->『分裂』
『他们甚至不知道代码间如果跳转』->『他们甚至不知道该跳转到何处』
| 名为 `step*` 的函数都是单一使用的,他们被创建的唯一作用就是避免“回调金字塔”。没有人会在动作链之外重复使用它们。因此这里的命名空间非常杂乱。 | ||
|
|
||
| We'd like to have a something better. | ||
| 或许还有其他方法。 |
| @@ -1,15 +1,15 @@ | |||
|
|
|||
| # Animated circle with callback | |||
| # 带有回调的圆形动画 | |||
| # 带有回调的圆形动画 | ||
|
|
||
| In the task <info:task/animate-circle> an animated growing circle is shown. | ||
| 在 <info:task/animate-circle> 任务中,显示了一个正在变大的圆形动画。 |
| 在 <info:task/animate-circle> 任务中,显示了一个正在变大的圆形动画。 | ||
|
|
||
| Now let's say we need not just a circle, but to show a message inside it. The message should appear *after* the animation is complete (the circle is fully grown), otherwise it would look ugly. | ||
| 假设我们现在不只是需要一个圆形,还要在其中显示信息。信息应该在动画完整出现**之后**出现(圆形已经完全长大了),否则圆形会看起来很难看。 |
Member
Member
|
@Starriers 修改下吧 |
Contributor
Author
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.
翻译完成