Superclass constructor

function Animal(name) {
  this.name=name;
  this.sleep = function () {
    console.log('is sleep')
  }
}
Animal.prototype.eat =function (food) {
  console.log(this.name+' is eating ' +food)
}
Copy the code

Prototype inheritance

Cannot pass a parameter to a parent method

function Cat() {
  
}
Cat.prototype = new Animal()
Cat.prototype.name ='122'
Copy the code

Constructor inheritance

Methods on the superclass prototype are not available

function Cat() { Animal.call(this,... arguments) }Copy the code

Combination of inheritance

Call the constructor of the parent class multiple times

function Cat(name) { Animal.call(this,... arguments) } Cat.prototype = new Animal()Copy the code

Parasitic inheritance

Prototype can’t be reused

function Cat(name) {
  var o  = Object.create(Animal.prototype)
  o.yy = function () {
    console.log('haha')
  }
}
Copy the code

Parasitic combinatorial inheritance

function Cat(name) { Animal.call(this,... Var o = object.create (animal.prototype)// Create a copy of the prototype of the parent class Cat. protpType = o // The prototype of the subclass points to a copy of the parent class}Copy the code

The class extends inheritance

Parasitic composite inheritance and Class Inheritance Parasitic composite inheritance creates a copy of the parent class, which the class uses directly