es5 inheritance es6 inheritance
Code
function Parent(content){
this.content = content
}
Parent.prototype.say = function(){
console.log(this.content)
}
function Child(content){
Parent.call(this, content)
}
let child = new Child('inherit')
console.log(child , 'child ')
function Child_1(content){
Parent.call(this, content)
}
Child_1.prototype = new Child_1()
let child_1 = new Child_1('inherit')
console.log(child_1 , 'child_1 ')
function Child_2(content){
Parent.call(this, content)
}
let p = Parent.prototype
p.constructor = Child_2
Child_2.prototype = p
let child_2 = new Child_2('inherit')
console.log(child_2 , 'child_2 ')
class Parent_{
constructor(content){
this.content = content
}
say(){
console.log(this.content)
}
}
class Child_ extends Parent_{
constructor(content){
super(content)
}
}
console.log(Child_ , 'Child_ ')