New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
对象的键、值、项 #140
对象的键、值、项 #140
Conversation
@leviding 翻译完成,不好意思,拖了这么久 |
@allenlongbaobao get |
校对认领 @leviding |
@trexguo ok |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
第一次校订 @leviding @allenlongbaobao
|
||
There is a `salaries` object with arbitrary number of salaries. | ||
有一个 `salaries` 对象,包含了薪水的值。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『有一个 salaries
对象,包含了薪水的值。』 => 『有一个 salaries
对象,包含了任意数量的薪水。』
|
||
Write the function `sumSalaries(salaries)` that returns the sum of all salaries using `Object.values` and the `for..of` loop. | ||
写一个 `sumSalaries(salaries)` 函数,使用 `Object.values` 和 `for..of` 循环语句返回所有薪水的和。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『写一个 sumSalaries(salaries)
函数,使用 Object.values
和 for..of
循环语句返回所有薪水的和。』 => 『使用 Object.values
和 for..of
循环语句写一个可以返回所有薪水的和的函数sumSalaries(salaries)
』
|
||
Write a function `count(obj)` that returns the number of properties in the object: | ||
写一个 `count(obj)` 函数返回一个对象的属性数量: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『写一个 count(obj)
函数返回一个对象的属性数量:』 => 『写一个可以返回对象的属性数量的函数 count(obj)
:』
|
||
Plain objects also support similar methods, but the syntax is a bit different. | ||
纯对象也支持这些方法,但是语法上有一些不同 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『纯对象也支持这些方法,但是语法上有一些不同』 => 『纯对象也支持类似的方法,但是语法有一些不同。』
注意标点和形容词similar
- [Object.keys(obj)](mdn:js/Object/keys) -- returns an array of keys. | ||
- [Object.values(obj)](mdn:js/Object/values) -- returns an array of values. | ||
- [Object.entries(obj)](mdn:js/Object/entries) -- returns an array of `[key, value]` pairs. | ||
- [Object.keys(obj)](mdn:js/Object/keys) —— 返回包含所有键的数组。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『返回包含所有键的数组。』 => 『返回一个包含该对象全部的键的数组。』
“返回包含所有键的数组”这句话中的“所有”一词容易引发歧义。一个解释是“归XXX所拥有”,一个解释是“全部的”。
为避免歧义,建议改为“全部”
|
||
The second difference is that `Object.*` methods return "real" array objects, not just an iterable. That's mainly for historical reasons. | ||
第二个区别是 `Object.*` 方法返回的是「真正的」数组对象,而不是可迭代项。这主要是历史原因。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『第二个区别是 Object.*
方法返回的是「真正的」数组对象,而不是可迭代项。这主要是历史原因。』 => 『第二个区别是 Object.*
方法返回的是「真正的」数组对象,而不仅仅是一个可迭代项。这主要由于是历史原因。』
@@ -49,22 +49,22 @@ let user = { | |||
- `Object.values(user) = ["John", 30]` | |||
- `Object.entries(user) = [ ["name","John"], ["age",30] ]` | |||
|
|||
Here's an example of using `Object.values` to loop over property values: | |||
下面这个例子中,使用了 `Object.values` 在属性值上做循环操作: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『下面这个例子中,使用了 Object.values
在属性值上做循环操作:』 => 『这里有一个使用 Object.values
来遍历属性值的例子:』
|
||
```js run | ||
let user = { | ||
name: "John", | ||
age: 30 | ||
}; | ||
|
||
// loop over values | ||
// 循环所有的值 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『循环』 => 『遍历』
|
||
Usually that's convenient. But if we want symbolic keys too, then there's a separate method [Object.getOwnPropertySymbols](mdn:js/Object/getOwnPropertySymbols) that returns an array of only symbolic keys. Also, the method [Reflect.ownKeys(obj)](mdn:js/Reflect/ownKeys) returns *all* keys. | ||
通常这很方便。但是如果我们也想要获得 Symbol 类型的键,那么有另外不同的方法 [Object.getOwnPropertySymbols](mdn:js/Object/getOwnPropertySymbols) 它会返回一个只包含 Symbol 类型的键的数组。同样,[Reflect.ownKeys(obj)](mdn:js/Reflect/ownKeys) 返回「所有」键。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『同样,Reflect.ownKeys(obj) 返回「所有」键。』 => 『此外,Reflect.ownKeys(obj) 方法会返回「所有的」键。』
|
||
Usually that's convenient. But if we want symbolic keys too, then there's a separate method [Object.getOwnPropertySymbols](mdn:js/Object/getOwnPropertySymbols) that returns an array of only symbolic keys. Also, the method [Reflect.ownKeys(obj)](mdn:js/Reflect/ownKeys) returns *all* keys. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『它会返回一个只包含 Symbol 类型的键的数组。』
建议在最前面加一个逗号。
@@ -49,22 +49,23 @@ let user = { | |||
- `Object.values(user) = ["John", 30]` | |||
- `Object.entries(user) = [ ["name","John"], ["age",30] ]` | |||
|
|||
下面这个例子中,使用了 `Object.values` 在属性值上做循环操作: | |||
这里有一个使用 `Object.valuesa` 来遍历属性值的例子: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
valuesa 多了一个a
@leviding 校对认领 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
The first difference is that we have to call `Object.keys(obj)`, and not `obj.keys()`. | ||
第一个区别是在对象中我们的调用语法是 `Object.key(obj)`,而不是 `obj.key()`。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『Object.key(obj)
,而不是 obj.key()
。』=>『Object.keys(obj)
,而不是 obj.keys()
。』
@allenlongbaobao 可以修改啦 |
修改完毕,感谢校对。 |
很赞,整体没什么问题。 |
翻译完成 resolve #64