You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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,
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!
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**!
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`.
###### 13. What are the three phases of event propagation?
405
+
###### 13. 事件冒泡的三个阶段是什么?
406
406
407
407
- A: Target > Capturing > Bubbling
408
408
- B: Bubbling > Target > Capturing
@@ -414,7 +414,7 @@ We said that `this.firstName` equals `"Sarah"` and `this.lastName` equals `"Smit
414
414
415
415
#### 答案: D
416
416
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.
@@ -423,7 +423,7 @@ During the **capturing** phase, the event goes through the ancestor elements dow
423
423
424
424
---
425
425
426
-
###### 14. All object have prototypes.
426
+
###### 14. 所有对象都有原型。
427
427
428
428
- A: true
429
429
- B: false
@@ -433,7 +433,7 @@ During the **capturing** phase, the event goes through the ancestor elements dow
433
433
434
434
#### 答案: B
435
435
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.
0 commit comments