Skip to content

Commit 25539ce

Browse files
committed
minor
1 parent bc7d43c commit 25539ce

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

1-js/09-classes/02-class-inheritance/article.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ With constructors it gets a little bit tricky.
209209

210210
Till now, `Rabbit` did not have its own `constructor`.
211211

212-
According to the [specification](https://tc39.github.io/ecma262/#sec-runtime-semantics-classdefinitionevaluation), if a class extends another class and has no `constructor`, then the following `constructor` is generated:
212+
According to the [specification](https://tc39.github.io/ecma262/#sec-runtime-semantics-classdefinitionevaluation), if a class extends another class and has no `constructor`, then the following "empty" `constructor` is generated:
213213

214214
```js
215215
class Rabbit extends Animal {
@@ -309,15 +309,15 @@ alert(rabbit.earLength); // 10
309309

310310
Let's get a little deeper under the hood of `super`. We'll see some interesting things by the way.
311311

312-
First to say, from all that we've learned till now, it's impossible for `super` to work.
312+
First to say, from all that we've learned till now, it's impossible for `super` to work at all!
313313

314-
Yeah, indeed, let's ask ourselves, how it could technically work? When an object method runs, it gets the current object as `this`. If we call `super.method()` then, how to retrieve the `method`? Naturally, we need to take the `method` from the prototype of the current object. How, technically, we (or a JavaScript engine) can do it?
314+
Yeah, indeed, let's ask ourselves, how it could technically work? When an object method runs, it gets the current object as `this`. If we call `super.method()` then, it needs to retrieve the `method` from the prototype of the current object. How JavaScript engine should get the prototype of `this`?
315315

316-
Maybe we can get the method from `[[Prototype]]` of `this`, as `this.__proto__.method`? Unfortunately, that doesn't work.
316+
The task may seem simple, but it isn't. The engine could try to get the method from `[[Prototype]]` of `this`, as `this.__proto__.method`. Unfortunately, that doesn't work.
317317

318-
Let's try to do it. Without classes, using plain objects for the sake of simplicity.
318+
Let's demonstrate the problem. Without classes, using plain objects for the sake of simplicity.
319319

320-
Here, `rabbit.eat()` should call `animal.eat()` method of the parent object:
320+
In the example below, `rabbit.__proto__ = animal`. Now let's try: in `rabbit.eat()` we'll call `animal.eat()`, using `this.__proto__`:
321321

322322
```js run
323323
let animal = {
@@ -418,7 +418,7 @@ To provide the solution, JavaScript adds one more special internal property for
418418
419419
This actually violates the idea of "unbound" functions, because methods remember their objects. And `[[HomeObject]]` can't be changed, so this bound is forever. So that's a very important change in the language.
420420
421-
But this change is safe. `[[HomeObject]]` is used only for calling parent methods in `super`, to resolve the prototype. So it doesn't break compatibility.
421+
But this change is safe. `[[HomeObject]]` is used only for calling parent methods in `super`, to resolve the prototype. So it doesn't break compatibility. Regular method calls know nothing about `[[HomeObject]]`, it only matters for `super`.
422422

423423
Let's see how it works for `super` -- again, using plain objects:
424424

0 commit comments

Comments
 (0)