1-js/02-first-steps/02-structure and 03-strict-mode#31
Merged
Conversation
Co-authored-by: maoxiaoke <thebigyellowbee@qq.com> resolve #3
added 2 commits
April 17, 2018 13:43
Signed-off-by: sqrtthree <imsqrtthree@gmail.com>
Contributor
|
校对认领 @leviding |
Starriers
reviewed
Apr 22, 2018
| # 代码结构 | ||
|
|
||
| The first thing to study is the building blocks of the code. | ||
| 第一件事就是代码的构建块(building blocks)。 |
Contributor
There was a problem hiding this comment.
第一件事就是代码的构建块(building blocks) =》
第一件需要学习的事情就是构建代码块。
| ## 语句 | ||
|
|
||
| Statements are syntax constructs and commands that perform actions. | ||
| 语句是执行操作的语法结构和命令。 |
| 语句是执行操作的语法结构和命令。 | ||
|
|
||
| We've already seen a statement `alert('Hello, world!')`, which shows the message. | ||
| 我们已经见过语句 `alert('Hello, world!')`, 它用来显示消息。 |
| 我们已经见过语句 `alert('Hello, world!')`, 它用来显示消息。 | ||
|
|
||
| We can have as many statements in the code as we want. Another statement can be separated with a semicolon. | ||
| 我们可以在代码中拥有尽可能多的语句。语句之间可以使用分号分割。 |
Contributor
There was a problem hiding this comment.
我们可以在代码中拥有尽可能多的语句 =》
我们可以在代码中编写任意数量的语句。
| ``` | ||
|
|
||
| Usually each statement is written on a separate line -- thus the code becomes more readable: | ||
| 通常,每条语句在单独的一行书写 -- 这让代码更易阅读。 |
Contributor
There was a problem hiding this comment.
破折号 用中文的
这让代码更易阅读 =》因此提高了代码的可读性
| 使用 `"use strict"` 与“默认”模式的区别仍然有待完善。 | ||
|
|
||
| In the next chapters, as we learn language features, we'll make notes about the differences of the strict mode. Luckily, there are not so many. And they actually make our life better. | ||
| 在接下来的章节中,当我们学习语言功能时,我们会记录严格模式的差异。幸运的是,没有那么多。它们实际上让我们的生活更美好。 |
Contributor
There was a problem hiding this comment.
它们实际上让我们的生活更美好。=> 实际上,它们为我们编写代码提供了极大的便利。
| 2. The strict mode is enabled by `"use strict"` at the top. Also there are several language features like "classes" and "modules" that enable strict mode automatically. | ||
| 3. The strict mode is supported by all modern browsers. | ||
| 4. It's always recommended to start scripts with `"use strict"`. All examples in this tutorial assume so, unless (very rarely) specified otherwise. | ||
| 1. `"use strict"` 指令将浏览器引擎转换为 “现代” 模式,改变一些内建特性的行为。 |
| 这有利于不破坏现有的规范,但缺点是 JavaScript 创造者的任何错误和不完美的考虑也永远地停留在语言中。 | ||
|
|
||
| It had been so until 2009 when ECMAScript 5 (ES5) appeared. It added new features to the language and modified some of the existing ones. To keep the old code working, most modifications are off by default. One needs to enable them explicitly with a special directive `"use strict"`. | ||
| 直到 2009 年 ECMAScript 5 (ES5) 的出现。ES5 规范增加了新的语言特性并且修改了一些已经存在的特性。为了保证旧的功能能够使用,大部分的修改是默认不生效的。你需要一个特殊的指令 `"use strict"` 来明确地使用这些特性。 |
| 没有 `/*...*/` 内嵌套另一个 `/*...*/`。 | ||
|
|
||
| Such code will die with an error: | ||
| 下面这段代码会死机、出错: |
| ```` | ||
|
|
||
| It's recommended to put semicolons between statements even if they are separated by newlines. This rule is widely adopted by the community. Let's note once again -- *it is possible* to leave out semicolons most of the time. But it's safer -- especially for a beginner -- to use them. | ||
| 如果语句被换行分割,非常建议在语句之间添加分号。这个规则被社区广泛采纳。让我们再次强调 -- 大部分时候可以省略分号,但是最好是,尤其对于新手,加上它。 |
Signed-off-by: sqrtthree <imsqrtthree@gmail.com>
leviding
reviewed
Apr 23, 2018
| ## "use strict" | ||
|
|
||
| The directive looks like a string: `"use strict"` or `'use strict'`. When it is located on the top of the script, then the whole script works the "modern" way. | ||
| 这个指令看上去是一个字符串 `"use strict"` 或者 `'use strict'`。当它处于脚本文件的顶部,则整个脚本文件都工作在 "现代" 的方式中。 |
| ``` | ||
|
|
||
| **Multiline comments start with a forward slash and an asterisk <code>/*</code> and end with an asterisk and a forward slash <code>*/</code>.** | ||
| **多行注释以一个正斜杠和星号开始 <code>"/*"</code> 并以一个星号和正斜杆结束 <code>"*/"</code>.** |
| 这一行的剩余部分是注释。它可能占据它所拥有的整行或者跟随在一条语句的后面。 | ||
|
|
||
| Like here: | ||
| 就像这样: |
| 现在,如果我们运行代码,仅仅第一个 `alert` 显示了文本,接着我们收到了一个错误! | ||
|
|
||
| But everything is fine again if we add a semicolon after `alert`: | ||
| 但是,如果我们在第一个 `alert` 后加入一个分号,就工作正常了。 |
| 语句是执行操作的语法结构和命令。 | ||
|
|
||
| We've already seen a statement `alert('Hello, world!')`, which shows the message. | ||
| 我们已经见过语句 `alert('Hello, world!')`, 可以用来显示消息。 |
Signed-off-by: sqrtthree <imsqrtthree@gmail.com>
Author
|
调整好了。 @leviding |
leviding
approved these changes
Apr 23, 2018
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.
Co-authored-by: maoxiaoke thebigyellowbee@qq.com
Cc @maoxiaoke
resolve #3