组合继承
利用原型链实现对父类型对象的方法继承
借用父类型的构造函数初始化相同属性
关键:子类型对象的原型为父类型的实例
function Person(name, age) {
this.name=name;
this.age=age;
}
Person.prototype.setname=function(name){
this.name=name;
}
function Student(name,age,price){
Person.call(this,name,age);//借用构造函数继承,子类型中调用父类型的构造函数,为 了得到属性
this.age=age;
}
Student.prototype=new Person();//子类型的原型为父类型的一个实例对象
console.log( Student.prototype.constructor);
Student.prototype.constructor=Student;//修正constructor属性
Student.prototype.setprice=function(price){
this.price=price;
}
var st=new Student("张三",15,1400);
console.log(st.__proto__.constructor);