Class inheritance

class Animal {
	constructor(color) {
    	this.color = color
    }
    move() {
    	/ /...}}class Dog extends Animal{
	constructor(color,name) {
   		super(color)
        this.name = name
    }
    say() {
    	/ /...}}Copy the code

Function inheritance

function Animal(color) {
	this.color = color
}
Animal.prototype.move = function(){}

function Dog(color,name) {
	Animal.apply(this.arguments)
   	this.name = name
}
// Do not add the say method on the prototype object of the Dog constructor. We will give him an empty object as the prototype and then add the say method on it

// The following three lines implement dog.prototype. __proto__ = animal.prototype
function Temp {}
Temp.prototype = Animal.prototype
Dog.prototype = new Temp()
Dog.prototype.constructor = Dog

Dog.prototype.say = function() {} 
Copy the code