class继承随笔

https://blog.csdn.net/friend1020/article/details/108157905

一方面,就 class 通过 BABEL 转化后的代码而言,子类在实例化时,如果子类存在构造函数需要执行时,即声明了 constructor 方法,那么一定要在 constructor 中先执行 super 方法,目的是执行父类的构造函数,实现继承父类的属性。

另一方面,子类的 constructor 中在 super 后使用的 this 是执行父类构造函数后的返回值。所以 super 需要在最开始执行。

 

原文地址:https://www.cnblogs.com/fengluzheweb/p/13600488.html