1, the concept of inheritance: take someone else's to become their own, but not affected by themselves. 2, JS in the most basic inheritance is the prototype inheritance. 3. Prototype inheritance: an instance object that points to the parent constructor by modifying the prototype of the child constructor. function Animal (name) { this.name=name; this.favor=[' eating ', ' sleeping ']; } cat.prototype=new Animal (' Kitty '); function Cat (color) { this.color=color; } var cat=new Cat (' Blue '); &nb Sp Cat.favor.push (' swimming '); var cat1=new cat (' Pink '); Console.log (cat.name+cat.color +cat.favor); Console.log (Cat1.name+cat1.color+cat1.favor); prototype Inheritance disadvantages: (1) You cannot pass parameters to a parent constructor. Here I'm new n creates an instance function of cat, but the name inside this function is still kitty. (2) data from a reference type in a parent constructor is shared by its own constructor instance. A swimming is added to the cat's favor, but CAT1 also has a swimming 4, which is borrowed from the constructor to inherit the parent's all-amount attribute. function Animal (name) { this.name=name; this.favor=[' eating ', ' Sleeping ']; }animal.prototype.say=function () { &NBsp Console.log (' hello '); }//This behavior does not inherit function Cat (color,name) { Animal.call (this,name) this.color=color; } var cat=new cat (' Blue ', ' Tom '); cat.favor.push (' swimming '); var cat1=new cat (' Pink ', ' Candy '); cat.say () Console.log (cat.name+ ' = = = ' +cat.color+ ' = = = ' +cat.favor); Cat1.say () Console.log (cat1.name+ ' = = = ' +cat1.color+ ' = = = ' +cat1.favor); The two drawbacks of prototype inheritance are solved by using constructor inheritance, but there are new problems. Members in the parent constructor prototype cannot be inherited. 5, combination inheritance function Animal (name) { this.name=name; this.favor=[' eating ', ' sleeping ']; } animal.prototype.say=function () { Console.log (' hello '); } function Cat (color,name) { Animal.call (this,name) this.color=color; }  Cat.prototype=new Animal (); var cat=new Cat (' Blue ', ' Tom '); cat.favor.push (' swimming ') ; var cat1=new Cat (' Pink ', ' Candy '); Cat.say () Console.log (cat.name+ ' = = = ' + cat.color+ ' = = = ' +cat.favor); Cat1.say () Console.log (cat1.name+ ' = = = ' +cat1.color+ ' = = = ' + Cat1.favor); Disadvantage: Although this method solves all the problems of appeal, the singular has a small shortcoming. The properties in the parent constructor are redundant (wasting memory).
Inheritance issues in
JS