class继承随笔

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

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

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

 

 

 

posted @ 2020-09-02 10:41  web-小强  阅读(130)  评论(0)    收藏  举报