Skip to content

Commit a637398

Browse files
authored
Merge pull request #303 from usernamehw/patch-3
Update article.md
2 parents 89f6c41 + 9437d9e commit a637398

File tree

1 file changed

+9
-9
lines changed
  • 1-js/07-object-oriented-programming/10-class-inheritance

1 file changed

+9
-9
lines changed

1-js/07-object-oriented-programming/10-class-inheritance/article.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ setTimeout(function() { super.stop() }, 1000);
161161

162162
## Overriding constructor
163163

164-
With constructors, things are is a little bit tricky.
164+
With constructors it gets a little bit tricky.
165165

166166
Till now, `Rabbit` did not have its own `constructor`.
167167

@@ -279,7 +279,7 @@ Here, `rabbit.eat()` should call `animal.eat()` method of the parent object:
279279
let animal = {
280280
name: "Animal",
281281
eat() {
282-
alert(this.name + " eats.");
282+
alert(`${this.name} eats.`);
283283
}
284284
};
285285

@@ -307,7 +307,7 @@ Now let's add one more object to the chain. We'll see how things break:
307307
let animal = {
308308
name: "Animal",
309309
eat() {
310-
alert(this.name + " eats.");
310+
alert(`${this.name} eats.`);
311311
}
312312
};
313313

@@ -332,7 +332,7 @@ longEar.eat(); // Error: Maximum call stack size exceeded
332332
*/!*
333333
```
334334

335-
The code doesn't work any more! We can see the error trying to call `longEar.eat()`.
335+
The code doesn't work anymore! We can see the error trying to call `longEar.eat()`.
336336

337337
It may be not that obvious, but if we trace `longEar.eat()` call, then we can see why. In both lines `(*)` and `(**)` the value of `this` is the current object (`longEar`). That's essential: all object methods get the current object as `this`, not a prototype or something.
338338

@@ -382,7 +382,7 @@ Let's see how it works for `super` -- again, using plain objects:
382382
let animal = {
383383
name: "Animal",
384384
eat() { // [[HomeObject]] == animal
385-
alert(this.name + " eats.");
385+
alert(`${this.name} eats.`);
386386
}
387387
};
388388
@@ -490,10 +490,10 @@ class Animal {}
490490
class Rabbit extends Animal {}
491491

492492
// for static propertites and methods
493-
alert(Rabbit.__proto__ == Animal); // true
493+
alert(Rabbit.__proto__ === Animal); // true
494494

495495
// and the next step is Function.prototype
496-
alert(Animal.__proto__ == Function.prototype); // true
496+
alert(Animal.__proto__ === Function.prototype); // true
497497

498498
// that's in addition to the "normal" prototype chain for object methods
499499
alert(Rabbit.prototype.__proto__ === Animal.prototype);
@@ -523,7 +523,7 @@ For instance, here `PowerArray` inherits from the native `Array`:
523523
// add one more method to it (can do more)
524524
class PowerArray extends Array {
525525
isEmpty() {
526-
return this.length == 0;
526+
return this.length === 0;
527527
}
528528
}
529529

@@ -551,7 +551,7 @@ For example, here due to `Symbol.species` built-in methods like `map`, `filter`
551551
```js run
552552
class PowerArray extends Array {
553553
isEmpty() {
554-
return this.length == 0;
554+
return this.length === 0;
555555
}
556556

557557
*!*

0 commit comments

Comments
 (0)