Skip to content

Commit bf8230c

Browse files
committed
question 11-15
1 parent da8941a commit bf8230c

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

README-zh_CN.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -331,16 +331,16 @@ bark.animal = 'dog'
331331

332332
```javascript
333333
function Person(firstName, lastName) {
334-
this.firstName = firstName
335-
this.lastName = lastName
334+
this.firstName = firstName;
335+
this.lastName = lastName;
336336
}
337337

338-
const member = new Person('Lydia', 'Hallie')
339-
Person.getFullName = function() {
340-
return `${this.firstName} ${this.lastName}`
338+
const member = new Person("Lydia", "Hallie");
339+
Person.getFullName = function () {
340+
return `${this.firstName} ${this.lastName}`;
341341
}
342342

343-
console.log(member.getFullName())
343+
console.log(member.getFullName());
344344
```
345345

346346
- A: `TypeError`
@@ -353,15 +353,15 @@ console.log(member.getFullName())
353353

354354
#### 答案: A
355355

356-
You can't add properties to a constructor like you can with regular objects. If you want to add a feature to all objects at once, you have to use the prototype instead. So in this case,
356+
你不能像常规对象那样,给构造函数添加属性。如果你想一次性给所有实例添加特性,你应该使用原型。因此本例中,使用如下方式:
357357

358358
```js
359-
Person.prototype.getFullName = function() {
360-
return `${this.firstName} ${this.lastName}`
359+
Person.prototype.getFullName = function () {
360+
return `${this.firstName} ${this.lastName}`;
361361
}
362362
```
363363

364-
would have made `member.getFullName()` work. Why is this beneficial? Say that we added this method to the constructor itself. Maybe not every `Person` instance needed this method. This would waste a lot of memory space, since they would still have that property, which takes of memory space for each instance. Instead, if we only add it to the prototype, we just have it at one spot in memory, yet they all have access to it!
364+
这才会使 `member.getFullName()` 起作用。为什么这么做有益的?假设我们将这个方法添加到构造函数本身里。也许不是每个 `Person` 实例都需要这个方法。这将浪费大量内存空间,因为它们仍然具有该属性,这将占用每个实例的内存空间。相反,如果我们只将它添加到原型中,那么它只存在于内存中的一个位置,但是所有实例都可以访问它!
365365

366366
</p>
367367
</details>
@@ -393,16 +393,16 @@ console.log(sarah)
393393

394394
#### 答案: A
395395

396-
For `sarah`, we didn't use the `new` keyword. When using `new`, it refers to the new empty object we create. However, if you don't add `new` it refers to the **global object**!
396+
对于 `sarah`,我们没有使用 `new` 关键字。当使用 `new` 时,`this` 引用我们创建的空对象。当使用了 `new``this` 引用的是**全局对象**global object)。
397397

398-
We said that `this.firstName` equals `"Sarah"` and `this.lastName` equals `"Smith"`. What we actually did, is defining `global.firstName = 'Sarah'` and `global.lastName = 'Smith'`. `sarah` itself is left `undefined`.
398+
我们说 `this.firstName` 等于 `"Sarah"`,并且 `this.lastName` 等于 `"Smith"`。实际上我们做的是,定义了 `global.firstName = 'Sarah'` `global.lastName = 'Smith'`。而 `sarah` 本身是 `undefined`.
399399

400400
</p>
401401
</details>
402402

403403
---
404404

405-
###### 13. What are the three phases of event propagation?
405+
###### 13. 事件冒泡的三个阶段是什么?
406406

407407
- A: Target > Capturing > Bubbling
408408
- B: Bubbling > Target > Capturing
@@ -414,7 +414,7 @@ We said that `this.firstName` equals `"Sarah"` and `this.lastName` equals `"Smit
414414

415415
#### 答案: D
416416

417-
During the **capturing** phase, the event goes through the ancestor elements down to the target element. It then reaches the **target** element, and **bubbling** begins.
417+
**捕获**capturing)阶段中,事件从祖先元素向下传播到目标元素。当事件达到**目标**target)元素后,**冒泡**bubbling)才开始。
418418

419419
<img src="https://i.imgur.com/N18oRgd.png" width="200">
420420

@@ -423,7 +423,7 @@ During the **capturing** phase, the event goes through the ancestor elements dow
423423

424424
---
425425

426-
###### 14. All object have prototypes.
426+
###### 14. 所有对象都有原型。
427427

428428
- A: true
429429
- B: false
@@ -433,7 +433,7 @@ During the **capturing** phase, the event goes through the ancestor elements dow
433433

434434
#### 答案: B
435435

436-
All objects have prototypes, except for the **base object**. The base object has access to some methods and properties, such as `.toString`. This is the reason why you can use built-in JavaScript methods! All of such methods are available on the prototype. Although JavaScript can't find it directly on your object, it goes down the prototype chain and finds it there, which makes it accessible for you.
436+
除了**基对象**base object),所有对象都有原型。基对象可以访问一些方法和属性,比如 `.tostring`。这就是为什么你可以使用内置的 JavaScript 方法!所有这些方法在原型上都是可用的。虽然 JavaScript 不能直接在对象上找到这些方法,但 JavaScript 会沿着原型链找到它们,以便于你使用。
437437

438438
</p>
439439
</details>

0 commit comments

Comments
 (0)