原理:
在子类里面通过调用父类、等同于子类里面把父类复制过来了
代码理解
// 父类function SuperType(){this.name = 'p';}SuperType.prototype.getName = function() {return this.name;}// 子类function SubType(){this.age = 18;SuperType.call(this)}SubType.prototype.getAge = function() {return this.name;}let instance = new SubType();console.log(instance)// { age: 18, name: "p" }
缺点
- 无法实现复用、每次去构建实例都需要重新去执行下父类
- 无法继承父类的原型方法
