JavaScript inheritance is something explained by a million people in a million different ways. It can be explained so simple, because correct inheritance only takes two simple steps to achieve. Prototype chaining and constructor stealing is all you need. This is my very simple explanation.
JavaScript inheritance is all about prototype chaining. To create one, simply set the prototype of an instance of a subtype equal to the one of an instance of the supertype. I use Object.create() for that.
There is one problem though: how to inherite the supertype’s properties?.
This is where constructor stealing comes in.
Constructor stealing
The subtype can inherit supertypes properties, by calling the constructor of the supertype. I use call() for that. Of course apply() can be used instead, if you prefer it.
The combination of prototype chaining and constructor stealing is called pseudo classical inheritance, because it is not exactly like in class based languages, but does behave the same.
The last problem that remains is how to access the supertype’s methods?
Accessing supertype methods
To access the supertype’s methods, simply call them directly on the prototype. Once again I use call() for that. Again apply() can be used instead.