In fact, I saw the implementation of inheritance when I first learned JavaScript. At that time, I just tried to understand the code snippet from the book. Today, I think again. It seems that this is the result of the evolution of thinking exploration. Inheritance, that is, reuse. If we leave the inherent idea of inheritance aside and allow B to reuse members of a, the simplest and most crude practice is ba; then the problem arises: any changes to B, it's just a change to a (the same object). In fact, when I first learned JS, I saw the implementation of inheritance. At that time, I just tried to understand the code snippet from the book. Today, I think again. It seems that this is the result of the evolution of thinking exploration.
Inheritance, that is, reuse.
If we leave aside the inherent idea of inheritance and allow B to reuse members of a, the simplest and most crude practice is B =;
So the question is: any change to B is a change to a (the same object ).
Okay, copy one copy. If the shortest copy is not secure enough, use the deep copy.
Problem: code is reused, but memory is wasted (both variables and methods are objects in JS ).
Do not copy, read-only, do not write, you can use the JS prototype, B. proto =. Generally, we do not directly change proto, which is too violent. JS provides a method that can be "mild" to achieve the goal-Object. create (B ).
The above is the most basic inheritance. How can a subclass more commonly call the constructor and members of the parent class (such as this. _ super), how to more commonly implement the inheritance mode (such as A = inheritFrom (B), and so on, not in the scope of this article ^ O ^
The above is a detailed description of the Inheritance (recommended) of JavaScript classes. For more information, see other related articles in the first PHP community!