🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
>[danger]组合继承 ----- 解决子类对象, 共享父类的, 引用类型数据 ~~~ function Person(){ this.name = "person"; this.grade = { math: 0 } } function Student() { Person.apply(this); // 当下面new Student() 这里都会调用父类 } Student.prototype = new Person(); // 第一次调用父类 let stu1 = new Student(); stu1.name = "100"; stu1.grade.math = 100; let stu2 = new Student(); console.log(stu2.name); // person console.log(stu2.grade.math); // 0 (不在共享引用数据了) console.log(stu2.grade === stu1.grade); // false ~~~ >新的问题是, 多次触发了父类构造函数, 如何解决呢? ---- 看最终版, [寄生组合继承](%E5%AF%84%E7%94%9F%E7%BB%84%E5%90%88%E7%BB%A7%E6%89%BF.md)