原理:
通过原型链 + 构造函数实现组合式继承
代码理解
// 父类function SuperType(){this.name = 'p';}SuperType.prototype.getName = function() {return this.name;}// 子类function SubType(){this.age = 18;SuperType.call(this) // 第二次执行}SubType.prototype = new SuperType(); // 第一次执行SubType.constructor = SubType;SubType.prototype.getAge = function() {return this.name;}let instance = new SubType();
缺点
- 多次调用父类、保存一些重复性的数据
