I am trying to understand how classes are working behind the scenes in ES6
and one thing that is rather unclear is how the prototypes are set for the child class. Here is the article I am reading:
https://medium.com/@robertgrosse/how-es6-classes-really-work-and-how-to-build-your-own-fd6085eb326a
There we see the following two lines:
Object.setPrototypeOf(Child, Base);
Object.setPrototypeOf(Child.prototype, Base.prototype);
When we create a Child
class, since Child
is a constructor function behind the scenes, I would expect Child.prototype
to be used for its creation, so the second line in the inheritance explanation is clear for me:
Object.setPrototypeOf(Child.prototype, Base.prototype);
However, whats the purpose of the first line - Object.setPrototypeOf(Child, Base);
- and how it is useful?
(I might not clearly understand the second line either though fully too)