Skip to content

1-js/02-first-steps/02-structure and 03-strict-mode#31

Merged
leviding merged 5 commits intozh-hansfrom
transfer/structure-and-strict-mode
Apr 23, 2018
Merged

1-js/02-first-steps/02-structure and 03-strict-mode#31
leviding merged 5 commits intozh-hansfrom
transfer/structure-and-strict-mode

Conversation

@linhe0x0
Copy link
Copy Markdown

@linhe0x0 linhe0x0 commented Apr 9, 2018

Co-authored-by: maoxiaoke thebigyellowbee@qq.com

Cc @maoxiaoke

resolve #3

Co-authored-by: maoxiaoke <thebigyellowbee@qq.com>

resolve #3
@linhe0x0 linhe0x0 changed the title 1-js/02-first-steps/02-structure and 03-strict-mode [WIP] 1-js/02-first-steps/02-structure and 03-strict-mode Apr 11, 2018
@leviding leviding added the WIP Work in process label Apr 12, 2018
sqrtthree added 2 commits April 17, 2018 13:43
@linhe0x0 linhe0x0 self-assigned this Apr 17, 2018
@linhe0x0 linhe0x0 removed the WIP Work in process label Apr 17, 2018
@linhe0x0 linhe0x0 changed the title [WIP] 1-js/02-first-steps/02-structure and 03-strict-mode 1-js/02-first-steps/02-structure and 03-strict-mode Apr 17, 2018
@Starriers
Copy link
Copy Markdown
Contributor

校对认领 @leviding

Copy link
Copy Markdown
Contributor

@Starriers Starriers left a comment

Choose a reason for hiding this comment

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

@sqrthree @leviding 校对完成

# 代码结构

The first thing to study is the building blocks of the code.
第一件事就是代码的构建块(building blocks)。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

第一件事就是代码的构建块(building blocks) =》
第一件需要学习的事情就是构建代码块。

## 语句

Statements are syntax constructs and commands that perform actions.
语句是执行操作的语法结构和命令。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

操作 =》 动作
个人感觉翻译成 动作会更好

语句是执行操作的语法结构和命令。

We've already seen a statement `alert('Hello, world!')`, which shows the message.
我们已经见过语句 `alert('Hello, world!')`, 它用来显示消息。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

, 它 =》 可以

我们已经见过语句 `alert('Hello, world!')`, 它用来显示消息。

We can have as many statements in the code as we want. Another statement can be separated with a semicolon.
我们可以在代码中拥有尽可能多的语句。语句之间可以使用分号分割。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

我们可以在代码中拥有尽可能多的语句 =》
我们可以在代码中编写任意数量的语句。

```

Usually each statement is written on a separate line -- thus the code becomes more readable:
通常,每条语句在单独的一行书写 -- 这让代码更易阅读。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

破折号 用中文的
这让代码更易阅读 =》因此提高了代码的可读性

使用 `"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.
在接下来的章节中,当我们学习语言功能时,我们会记录严格模式的差异。幸运的是,没有那么多。它们实际上让我们的生活更美好。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

它们实际上让我们的生活更美好。=> 实际上,它们为我们编写代码提供了极大的便利。

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"` 指令将浏览器引擎转换为 “现代” 模式,改变一些内建特性的行为。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

少翻译了。
我们会在之后的学习中了解这些细节。

这有利于不破坏现有的规范,但缺点是 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"` 来明确地使用这些特性。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

在特殊指令后加上 破折号会更好(中文破折号)

没有 `/*...*/` 内嵌套另一个 `/*...*/`

Such code will die with an error:
下面这段代码会死机、出错:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

die 翻译成死机很奇怪

````

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.
如果语句被换行分割,非常建议在语句之间添加分号。这个规则被社区广泛采纳。让我们再次强调 -- 大部分时候可以省略分号,但是最好是,尤其对于新手,加上它。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

破折号用中文的

Signed-off-by: sqrtthree <imsqrtthree@gmail.com>
## "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'`。当它处于脚本文件的顶部,则整个脚本文件都工作在 "现代" 的方式中。
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

在 "现代" 的方式中 => 在“现代”的方式中

```

**Multiline comments start with a forward slash and an asterisk <code>/&#42;</code> and end with an asterisk and a forward slash <code>&#42;/</code>.**
**多行注释以一个正斜杠和星号开始 <code>"/&#42;"</code> 并以一个星号和正斜杆结束 <code>"&#42;/"</code>.**
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

结尾句号用全角

这一行的剩余部分是注释。它可能占据它所拥有的整行或者跟随在一条语句的后面。

Like here:
就像这样:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

分号全角

现在,如果我们运行代码,仅仅第一个 `alert` 显示了文本,接着我们收到了一个错误!

But everything is fine again if we add a semicolon after `alert`:
但是,如果我们在第一个 `alert` 后加入一个分号,就工作正常了。
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

结尾应该用冒号吧?

语句是执行操作的语法结构和命令。

We've already seen a statement `alert('Hello, world!')`, which shows the message.
我们已经见过语句 `alert('Hello, world!')`, 可以用来显示消息。
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

可以用来显示消息前面多一个空格

Signed-off-by: sqrtthree <imsqrtthree@gmail.com>
@linhe0x0
Copy link
Copy Markdown
Author

调整好了。 @leviding

@leviding leviding merged commit 5171127 into zh-hans Apr 23, 2018
@leviding leviding deleted the transfer/structure-and-strict-mode branch April 23, 2018 05:17
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.

3 participants