构造函数的继承性
function people(name,age,color){
this.name=name
this.age=age
this.color=color
}
people.prototype.move=function(){
console.log(this.age+"的"+this.name+"正在工作")
}
people.prototype.sleep=function(){
console.log(this.age+"的"+this.name+"正在睡觉")
}
function student(name,age,color){
}
//原型链继承
student.prototype=new people("王一",18,"黑色");
student.prototype.mystudents=function(){
console.log("学习")
}
var s1=new student()
s1.move()
//冒充继承
function teacher(name,age,color){
people.call(this,name,age,color)
}
teacher.prototype.ming=function(){
console.log("上班")
}
var lao2=new teacher("老2",33,"白色")
console.log(lao2)
lao2.move()
//混合继承:原型链继承+冒充继承
function patriarch(name,age,color){
people.call(this,name,age,color)
}
patriarch.prototype=new people()
patriarch.prototype.zhang=function(){
console.log("教训孩子")
}
var jia=new patriarch("家1",35,"教育")
jia.move()
//1.通过原型链继承 存在问题:无法对父类的属性进行初始化,所有的对象的所有属性都是相同的,可以通过 call或者apply方法来实现
//2.冒充继承:存在问题 无法继承 父类的原型中的方法
//3.混合继承:原型链继承+冒充继承 最优