- ES6之前并没有给我们提供extends继承。我们可以通过构造函数+原型对象模拟实现继承,被称为组合继承。
- call() 调用这个函数,并且修改函数运行时的this指向

- 借用构造函数继承父类型属性
核心原理:通过call() 把父类型的this指向子类型的this,这样就可以实现子类型继承父类型的属性。

function Father(uname, age) {
this.uname = uname;
this.age = age;
}
Father.prototype.money = function() {
console.log(100000);
};
//子构造函数
function Son(uname, age) {
Father.call(this, uname, age);
}
//这种方法会影响父函数
// Son.prototype = Father.prototype;
Son.prototype = new Father();
//如果利用对象的形式修改了原型对象,别忘了利用constructor指回原来的构造函数
Son.prototype.constructor = Son;
//这个是子构造函数专门的方法
Son.prototype.exam = function() {
console.log('考试');
}
var son = new Son('l', 12);
console.log(son);
console.log(Son.prototype.constructor);