Skip to content

Commit 9633667

Browse files
authored
Update translation of 1-js/08-prototypes/04-prototype-methods (javascript-tutorial#636)
Update translation of 1-js/08-prototypes/04-prototype-methods (javascript-tutorial#636)
1 parent 044f503 commit 9633667

5 files changed

Lines changed: 100 additions & 146 deletions

File tree

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

2-
可以使用 `Object.keys` 列出所有可枚举键值,然后输出
2+
可以使用 `Object.keys` 获取所有可枚举的键,并输出其列表
33

4-
为了使 `toString` 不可枚举,我们使用属性描述器来定义它`Object.create` 语法允许我们为一个对象提供属性描述器作为第二参数。
4+
为了使 `toString` 不可枚举,我们使用一个属性描述器来定义它`Object.create` 语法允许我们为一个对象提供属性描述器作为第二参数。
55

66
```js run
77
*!*
88
let dictionary = Object.create(null, {
9-
 toString: { // 定义 toString 方法
10-
   value() { // value 是一个函数
9+
toString: { // 定义 toString 属性
10+
value() { // value 是一个 function
1111
return Object.keys(this).join();
1212
}
1313
}
@@ -17,13 +17,15 @@ let dictionary = Object.create(null, {
1717
dictionary.apple = "Apple";
1818
dictionary.__proto__ = "test";
1919

20-
// apple 和 __proto__ 在循环内
20+
// apple 和 __proto__ 在循环中
2121
for(let key in dictionary) {
22-
 alert(key); // "apple",然后 "__proto__"
22+
alert(key); // "apple",然后是 "__proto__"
2323
}
2424

25-
// 通过 toString 得到逗号分隔的属性值
26-
alert(dictionary.toString()); // "apple,__proto__"
25+
// 通过 toString 处理获得的以逗号分隔的属性列表
26+
alert(dictionary); // "apple,__proto__"
2727
```
2828

29-
当我们使用描述器创建一个属性,它的标识默认是 `false`。因此在以上代码中,`dictonary.toString` 是不可枚举的。
29+
当我们使用描述器创建一个属性,它的标识默认是 `false`。因此在上面这段代码中,`dictonary.toString` 是不可枚举的。
30+
31+
请阅读 [](info:property-descriptors) 一章进行回顾。

1-js/08-prototypes/04-prototype-methods/2-dictionary-tostring/task.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ importance: 5
22

33
---
44

5-
# 给字典对象添加 toString 方法
5+
# 为 dictionary 添加 toString 方法
66

7-
有一个对象 `dictionary`,通过 `Object.create(null)` 创建,用来存储任意键值对
7+
这儿有一个通过 `Object.create(null)` 创建的,用来存储任意 `key/value` 对的对象 `dictionary`
88

9-
为该对象添加方法 `dictionary.toString()`,返回所有键的列表,用逗号隔开。你的 `toString` 方法不能对该对象使用 `for...in`
9+
为该对象添加 `dictionary.toString()` 方法,该方法应该返回以逗号分隔的所有键的列表。你的 `toString` 方法不应该在使用 `for...in` 循环遍历数组的时候显现出来
1010

11-
以下是它的运行例子
11+
它的工作方式如下
1212

1313
```js
1414
let dictionary = Object.create(null);
1515

1616
*!*
17-
// 添加 dictionary.toString 方法的代码
17+
// 你的添加 dictionary.toString 方法的代码
1818
*/!*
1919

2020
// 添加一些数据
2121
dictionary.apple = "Apple";
22-
dictionary.__proto__ = "test"; // __proto__ 在这里是正常参数
22+
dictionary.__proto__ = "test"; // 这里 __proto__ 是一个常规的属性键
2323

24-
// 只有 apple 和 __proto__ 在循环内
24+
// 在循环中只有 apple 和 __proto__
2525
for(let key in dictionary) {
26-
 alert(key); // "apple",然后 "__proto__"
26+
alert(key); // "apple", then "__proto__"
2727
}
2828

29-
// your toString in action
29+
// 你的 toString 方法在发挥作用
3030
alert(dictionary); // "apple,__proto__"
3131
```

1-js/08-prototypes/04-prototype-methods/3-compare-calls/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
第一个调用中 `this == rabbit`,其他的 `this` 等同于 `Rabbit.prototype`因为它是逗号之前的对象
2+
第一个调用中 `this == rabbit`,其他的 `this` 等同于 `Rabbit.prototype`因为 `this` 就点符号前面的对象
33

4-
因此只有第一个调用显示 `Rabbit`其他的都是 `undefined`
4+
所以,只有第一个调用显示 `Rabbit`其他的都显示的是 `undefined`
55

66
```js run
77
function Rabbit(name) {

1-js/08-prototypes/04-prototype-methods/3-compare-calls/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Rabbit.prototype.sayHi = function() {
1717
let rabbit = new Rabbit("Rabbit");
1818
```
1919

20-
以下调用得到的结果是否相同
20+
以下调用做的是相同的事儿还是不同的
2121

2222
```js
2323
rabbit.sayHi();

0 commit comments

Comments
 (0)