Open zlx362211854 opened 4 years ago
多继承就是一个子类继承的属性和方法同时继承自多个父类。举个例子
function Mother(quotient) {
this.gender = 'female'
this.quotient = quotient
}
function Father(height) {
this.gender = 'male'
this.height = height
}
现在我想要一个Child构造函数,同时继承Mother和Father的所有属性,可以用call或apply来实现多继承:
function Mother(quotient) {
this.gender = 'female'
this.quotient = quotient
}
function Father(height) {
this.gender = 'male'
this.height = height
}
function Child(height, quotient) {
Father.call(this, height)
Mother.call(this, quotient)
}
var girl = new Child(165, 90)
console.log(girl)
// Child {gender: "female", height: 165, quotient: 90}
用类装饰器,模拟实现多继承:
Reference
ES6 Class Multiple inheritance