1-js/04-object-basics/01-object#143
Merged
leviding merged 26 commits intojavascript-tutorial:zh-hansfrom Jul 22, 2018
Merged
Conversation
|
@leviding 校对认领 |
Tivcrmn
suggested changes
Jul 3, 2018
| # 对象 | ||
|
|
||
| As we know from the chapter <info:types>, there are seven language types in JavaScript. Six of them are called "primitive", because their values contain only a single thing (be it a string or a number or whatever). | ||
| 正如我们从《引言:类型》中知道的那样,JS中有很多种类型。 有六种原始类型,因为他们只包含一种东西(字符串,数值或者什么之类) |
| 相反,对象用来存储键值对和更复杂的实体。在JS中,对象深入到这门语言的方方面面。所以在我们深入理解这门语言之前,我们必须理解对象。 | ||
|
|
||
| An object can be created with figure brackets `{…}` with an optional list of *properties*. A property is a "key: value" pair, where `key` is a string (also called a "property name"), and `value` can be anything. | ||
| 对象可以通过中括号`{…}`和其中包含一些可选的*属性*来创建。属性是一个键值对,键是一个字符串 (也叫做属性名), 值可以任何的什么. |
|  | ||
|
|
||
| An empty object ("empty cabinet") can be created using one of two syntaxes: | ||
| 我们可以额用下面的语法来创建一个空的对象(“空柜子”): |
There was a problem hiding this comment.
『我们可以额用下面的语法来创建一个空的对象(“空柜子”):』=>『我们可以用下面两种语法的任一种来创建一个空的对象(“空柜子”):』
| let user = {}; // "object literal" syntax | ||
| let user = new Object(); // “构造函数” 的语法 | ||
| let user = {}; // “对象文本” 的语法 | ||
| ``` |
|  | ||
|
|
||
| Usually, the figure brackets `{...}` are used. That declaration is called an *object literal*. | ||
| 通常,我们用中括号。这种方式我们叫做*对象文本* |
| 5. Remove the property `name` from the object. | ||
| 1. 创建一个空的`user`对象. | ||
| 2. 为这个对象增加一个属性,键是`name`值是`John`。 | ||
| 3. 在增加一个属性键`surname`值`Smith`。 |
| # 检查空对象 | ||
|
|
||
| Write the function `isEmpty(obj)` which returns `true` if the object has no properties, `false` otherwise. | ||
| 写一个方法`isEmpty(obj)`,当对象没有属性的时候返回 `true`,否自返回`false`。 |
| 当然,这没什么问题。 | ||
|
|
||
| The `const` only protects the variable itself from changing. | ||
| 关键字`const`保证对象本身不改变。 |
There was a problem hiding this comment.
『关键字const保证对象本身不改变。』=>『关键字const保证存储对象的变量本身不改变。』
| # 属性值求和 | ||
|
|
||
| We have an object storing salaries of our team: | ||
| 我们用一个对象保存我们的工资: |
| # 数值属性都乘以2 | ||
|
|
||
| Create a function `multiplyNumeric(obj)` that multiplies all numeric properties of `obj` by `2`. | ||
| 穿件一个`multiplyNumeric(obj)`方法,把`obj`所有的数值属性都乘以`2`。 |
Member
|
@MENQ 可以修改啦 |
leviding
reviewed
Jul 3, 2018
| 3. Add the property `surname` with the value `Smith`. | ||
| 4. Change the value of the `name` to `Pete`. | ||
| 5. Remove the property `name` from the object. | ||
| 1. 创建一个空的`user`对象. |
Member
There was a problem hiding this comment.
汉字与英文还有数字之间要有空格,但是逗号和句号等全角符号(不包括破折号)前后不管是什么,都不要空格。这只是格式要求的一小点,详细请见翻译计划 WIKI 的译者教程,根据译者教程中的格式要求部分修改全文的格式。
本行空格这样加:
创建一个空的 `user` 对象
此外,句号用中文的。
| @@ -1,14 +1,14 @@ | |||
| importance: 5 | |||
| 重要级别:5 | |||
| 3. Add the property `surname` with the value `Smith`. | ||
| 4. Change the value of the `name` to `Pete`. | ||
| 5. Remove the property `name` from the object. | ||
| 1. 创建一个空的`user`对象. |
Member
There was a problem hiding this comment.
汉字与英文还有数字之间要有空格,但是逗号和句号等全角符号(不包括破折号)前后不管是什么,都不要空格。这只是格式要求的一小点,详细请见翻译计划 WIKI 的译者教程,根据译者教程中的格式要求部分修改全文的格式。
本行空格这样加:
创建一个空的 `user` 对象
此外,句号用中文的。
Contributor
Author
|
@leviding OK |
Member
|
@MENQ 记得修改下哈 |
Contributor
Author
|
想起来了! |
Contributor
Author
|
@leviding 可以校对! |
leviding
approved these changes
Jul 22, 2018
Member
|
@MENQ 翻译辛苦了,但是格式还是要注意下哈,看看我的这些 commit 记录 |
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.




#23 迟了,不好意思!