javascript inheritance and standard OOP inheritance are very different, JavaScript inheritance is a prototype chain of technology, the following use the example to learn JS inheritance
JavaScript inheritance and standard OOP inheritance are very different, JavaScript inheritance is the use of prototype chain technology, each class will be "member variable" and "member function" on the prototype, js++ have superclass link it up, that is C.prototype.superclass = C.superclass = P.prototype; When var C = new C (), c.__proto__ = C.prototype; When C accesses a member variable, if the __proto__ cannot get it, it goes to the C.prototype lookup, and if it does not, it goes to the prototype of the parent class, because only __proto__ is allocated when the object is created (each object is allocated independently). All others are allocated when defined (shared by each object), at this point, if you are accessing a member variable in C.prototype that is an object, not modifying the member variable itself, but modifying the members of the member variable object, the members of the modified member variable object are shared by all object instances. This violates the original intention of the class design. For example, the code is as follows: ' Package '. J (function () { ' class A '. J (function () { &NBSP ; Jpublic (v:{a:1 } &NBSP ; }); Jprivate ({ p:{a:1 }   ; }); jprotected ({ x:{a:1 } &NB Sp }); }); ' class B extends A '. J (function () { }); }); var B1 = new B (); B1.V.A = 5; B1.X.A = 5; var b2 = new B (); Console.log (B1.V.A)/output is 5 console.log (B1.X.A)//output is 5 Console.log (B2.V.A)//output is also 5, not expected 1 Console.log (B2.X.A)//output is 1 console.log (B2.P.A)//unavailable, will prompt p does not exist How to solve this problem? A. A member "member variable" such as V, which is itself an object, is not defined on the prototype chain, but is called in the constructor, where an object instance is created and allocated on the object's __proto__. js++ provides a similar method, as long as the "member variable" or "member function" defined in Jprivate is assigned to the __proto__ of the object, and only this instance is available, the "member variable" defined in jprotected (which itself is an object) is also assigned to the object's __proto__. And only to inherit his availability, B. The prototype chain defines only the members of a read-only "member variable" (which itself is an object) the member variable defined by C.jpublic (which itself is an object). Only read-only members, remember that they are not assignable, or they will be shared in individual instances.