There are many types and implementations of inheritance in JavaScript in many books, basically two kinds: class inheritance (object impersonation) and prototype inheritance.
Class inheritance (Object impersonation): The method of defining its own properties inside a function, when the subclass inherits, using call or apply to implement the object impersonation, the type definition of things are copied, so that the inheritance subclass and the parent class is not much association, does not affect each other, it is beneficial to protect some of their own private properties.
Prototype inheritance: Each function has its own prototype (prototype) property, which is created automatically when the instance object is generated. It is also an object, with properties and methods that can be shared between instances. The properties and methods of the instance itself are included in the constructor. In other words, the properties and methods inside the constructor, after being instantiated, become local properties and methods, and the properties and methods in the prototype (prototype) are only a reference in the instance and can therefore be shared by multiple instances.
Both have advantages and disadvantages, and practical applications are mostly mixed applications.
Here's an example of mixing the two to understand:
function A (x) { This. x =x; } a.prototype.a="a"; function B (x, y) { This. y =y; A.call ( This, x);//class Inheritance} b.prototype.b1=function () {alert ("B1"); } B.prototype=NewA ();//prototype InheritanceB.PROTOTYPE.B2 =function () {alert ("B2"); } b.prototype.constructor=B; varobj =NewB1,3);
"JavaScript" Class Inheritance (object impersonation) and prototype inheritance __ deep understanding of prototypes and prototype chains