JS: Dive into Classes
Theory: Inheritance
Class inheritance allows the creation of subclasses based on base or superclasses, where subclasses inherit the structure of the base classes. In JavaScript, classes are essentially prototypes. Inheritance will be studied in stages throughout the course due to its complexity.
To illustrate inheritance, consider the HTML structure where each HTML tag has unique characteristics while sharing common attributes:
Specific elements represented by tags in HTML inherit this class:
We represent inheritance as "A extends B" indicating that A inherits B. Now let's see how inheritance works:
HTMLAnchorElement does not have a constructor definition but has access to all the properties of the superclass through inheritance. Methods not available in the current class, such as toString(), are automatically called from the parent class.
Chain of Inheritance
Unlike interfaces, JavaScript allows single-class inheritance.
It means we can inherit only one class to avoid problems related to multiple inheritances, such as method and property collisions. However, the chain of inheritance can be as deep as desired:
Type check operator
The instanceof operator considers classes from the prototype inheritance chain:
Don't forget that such checks mean you can't use polymorphism. Sometimes you can't do without them, but in the vast majority of cases it's better to be bound to the object interface.

