this article illustrates how JavaScript implements multiple inheritance. Share to you for your reference, as follows:

1. defines an empty class constructor, then by way of prototype to the parent class definition properties and methods of

2. defines an empty subclass constructor, then the subclass instance prototype binding superclass, then subclass the prototype of the parent class is also bound in the instance of the parent class. Set your own properties and methods for the subclass by means of prototype.

3. defines an empty sun class constructor, then binds the prototype of the sun class to the instance of the subclass, and binds the parent class of the grandson prototype to the instance of the subclass. Define your own attributes and methods for grandchildren by prototype.

4. instantiates a descendant class object, by calling the instance method call itself, can also call the superclass of the class is the sun in the class, also can directly call the parent class here is maximum superclass method, you can also add properties and methods for the current object.

 function Person ( {} = ""; / / create a name attribute Person.prototype.say = function for human (content) {// creates a way of talking to human if (! {/ / if the object does not exist name attributes, use the prototype chain name ("console.log =;} This is" + + ", I want to say" +content ");}; function (Parent) new (Parent.prototype = Person) {}; / / set the Parent class inheritance Person class Parent.prototype.superClass = new (Person); / / set superClass to save the parent class Person method attribute =" parents "; / / set Parent the name property of Parent.prototype.say = function ({//) Parent say set his method of console.log (" I'm a Parent class say method! ");}; function (Child) new (Child.prototype = Parent) {}; / / set the Child class inheritance Parent class Child.prototype.superClass = new (Parent); / / set superClass to save the parent class Parent method (function) attribute Child.prototype.say = {/ / set the Child say console.log method (" I am Child class say methods! ");} var C = new (Child); / / instantiate a Child object (c.say); / / say output method, call itself prototype: say method of the Child class! C.superClass.say (say); / / output method, call the parent class Parent: say method of the Parent class! C.superClass.superClass.say ("ha"); / / say superclass methods Person maximum direct calls (method this to Person), output: I am a man, I want to say "ha ha / call call with the largest class Person say method (method this to instantiate C, but at C and no name attribute, so is used in the Parent name (c)," hee hee "); / / output: I am a father, I want to say, =" sub class instance "; / / to the current object attribute is also increased name / / call say method is called Person (the largest parent class this has name property in the C object (C,;" I am the subclass to instantiate objects "); / / output: I am a subclass instance, I want to say I am 

< strong>ps: instantiate multiple inheritance sub classes can An attribute is added to the prototype object to save the objects and attributes of the parent class. When the subclass calls, it uses superClass to point out the parent class method, which solves the problem that the parent class and the subclass method have the same name, and the sub class will inherit the parent class method after inheriting the parent class.

more JavaScript on the relevant content of interested readers can see the special station: "javascript " Object-Oriented tutorial, "JavaScript " error and debugging skills summary, " JavaScript data structures and algorithms," "skills summary JavaScript traversal algorithm and skills summary " and "JavaScript

" math Usage Summary

the hope for all JavaScript programming help.

This concludes the body part