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
First, let's see why the latter code doesn't work.
1
+
Lad os først se på, hvorfor den sidste kode ikke virker.
2
2
3
-
The reason becomes obvious if we try to run it. An inheriting class constructor must call `super()`. Otherwise `"this"`won't be "defined".
3
+
Grunden til det bliver tydelig hvis vi prøver at køre den. En arvende klassekonstruktør skal kalde `super()`. Ellers vil `"this"`ikke være "defineret".
4
4
5
-
So here's the fix:
5
+
Så her er en måde at fixe det på:
6
6
7
7
```js run
8
8
classRabbitextendsObject {
9
9
constructor(name) {
10
10
*!*
11
-
super(); //need to call the parent constructor when inheriting
11
+
super(); //du skal kalde den overordnede konstruktør når du nedarver
12
12
*/!*
13
13
this.name= name;
14
14
}
@@ -19,16 +19,16 @@ let rabbit = new Rabbit("Rab");
19
19
alert( rabbit.hasOwnProperty('name') ); // true
20
20
```
21
21
22
-
But that's not all yet.
22
+
Men det er ikke alt.
23
23
24
-
Even after the fix, there's still an important difference between`"class Rabbit extends Object"`and`class Rabbit`.
24
+
Selv efter denne rettelse er der en vigtig forskel mellem`"class Rabbit extends Object"`og`class Rabbit`.
25
25
26
-
As we know, the "extends" syntax sets up two prototypes:
26
+
Som vi ved, opretter "extends" syntaksen to prototyper:
27
27
28
-
1.Between`"prototype"`of the constructor functions (for methods).
29
-
2.Between the constructor functions themselves (for static methods).
So`Rabbit`doesn't provide access to static methods of `Object`in that case.
68
+
Så`Rabbit`giver ikke adgang til de statiske metoder fra `Object`i det tilfælde.
69
69
70
-
By the way, `Function.prototype`also has "generic" function methods, like`call`, `bind`etc. They are ultimately available in both cases, because for the built-in`Object` constructor, `Object.__proto__ === Function.prototype`.
70
+
Forresten så har`Function.prototype`også en "generiske" function metoder, såsom`call`, `bind`osv. De er i sidste ende tilgængelige i begge tilfælde, fordi for den indbyggede`Object` constructor, `Object.__proto__ === Function.prototype`.
0 commit comments