Merge pull request #2992 from Rnbsov/patch-41

remove extra break lines and add missed
This commit is contained in:
Ilya Kantor 2022-05-12 16:01:19 +04:00 committed by GitHub
commit 2901e0c645
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -160,6 +160,7 @@ Now `Rabbit` has the `stop` method that calls the parent `super.stop()` in the p
As was mentioned in the chapter <info:arrow-functions>, arrow functions do not have `super`.
If accessed, it's taken from the outer function. For instance:
```js
class Rabbit extends Animal {
stop() {
@ -176,7 +177,6 @@ setTimeout(function() { super.stop() }, 1000);
```
````
## Overriding constructor
With constructors it gets a little bit tricky.
@ -280,8 +280,6 @@ alert(rabbit.earLength); // 10
*/!*
```
### Overriding class fields: a tricky note
```warn header="Advanced note"
@ -370,13 +368,12 @@ In our case, `Rabbit` is the derived class. There's no `constructor()` in it. As
So, `new Rabbit()` calls `super()`, thus executing the parent constructor, and (per the rule for derived classes) only after that its class fields are initialized. At the time of the parent constructor execution, there are no `Rabbit` class fields yet, that's why `Animal` fields are used.
This subtle difference between fields and methods is specific to JavaScript
This subtle difference between fields and methods is specific to JavaScript.
Luckily, this behavior only reveals itself if an overridden field is used in the parent constructor. Then it may be difficult to understand what's going on, so we're explaining it here.
If it becomes a problem, one can fix it by using methods or getters/setters instead of fields.
## Super: internals, [[HomeObject]]
```warn header="Advanced information"