原型链+借用构造函数的组合继承
-利用原型链实现对父类型对象的方法继承
-利用call()借用父类型构造函数初始化相同属性
举个栗子- 。-~~
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.price = price;
}
//为了能看到父类型的方法
Student.prototype = new Person();
//修正constructor属性
Student.prototype.constructor = Student;
Student.prototype.setPrice = function(price){
this.price = price;
}
var ss = new Student("小屋",11,133333);
ss.setName("小为");
ss.setPrice(3333);
console.log(ss);
输出结果: