实现多继承
function fathercalass(hobby,height){
this.hobby=hobby
this.height=height
}
fathercalass.prototype={
hobbya:'debugger',
settimea:function(){
console.log('sgdop')
}
}
function superclass(name,age){
this.name0=name
this.age0=age
}
superclass.prototype={
agea:'kfj',
setget:function(){
console.log('setget1')
return this // 支持链式调用
}
}
function sonclass(name,age,hobby,height){
superclass.call(this,name,age)
fathercalass.call(this,hobby,height)
}
sonclass.prototype=Object.create(Object.assign(fathercalass.prototype,superclass.prototype)) // 将两个原型的属性和方法合并后传递
var obj1= new sonclass('akj',23,'basketball','table')
console.log(obj1.agea,obj1.age0,obj1.name0) // 输出 kfj 23 akj
console.log(obj1.__proto__) // 包含了superclass 和fatherclass的原型上的方法和属性的对象
console.log(obj1.setget().setget().setget()) // return this 支持链式调用
console.log(obj1.hobby,obj1.height) // 输出 basketball table
只是将类式继承升级成了多继承 原理一样 注意 该处的Object.creat()和assign()都是属于浅拷贝 如果 原型属性中存在嵌套情况 请使用深拷贝