- 通过原型实现继承
function Baba(color){
this.color = color
}
Baba.prototype.say =function(){}
function Erzi(name,color){
Baba.call(this,color)
this.name = name
}
function temp (){}
temp.prototype = Baba.prototype
Erzi.prototype = new temp()
Erzi.prototype.constructor = Erzi
Erzi.prototype.cry = ()=>{}
var p1 = new Erzi('jack','red')
console.dir(p1)
- 通过class(类)实现继承
class Baba{
constructor(color){
this.color = color
}
say(){}
}
class Erzi extends Baba{
constructor(color,name){
super(color)
this.name = name
}
move(){}
}
var c1 = new Erzi('jack','red')
console.dir(c1)