您好,\n以下代码示例会引发错误:
\nTypeError: Super constructor null of SecondChild is not a constructor\n at new SecondChild (<anonymous>:8:19)\n at <anonymous>:49:13\n at dn (<anonymous>:16:5449)\nRun Code Online (Sandbox Code Playgroud)\n目前我正在尝试了解问题到底是什么以及如何在 typescript/javascript 中实现工厂模式。有几种行为我不太理解:
\n如果我实现父类而不使用类型“this”与工厂方法结合使用,则可以防止错误,但它看起来相当方便。抽象方法重复背后的目标是它返回一个子类实例。我可以在每个子类中实现它,但在我的现实世界项目中,复杂性要高得多。
\nsrc/\n child.ts\n factory.ts\n index.ts\n parent.ts\n main.ts\n second-child.ts\nRun Code Online (Sandbox Code Playgroud)\nTypeError: Super constructor null of SecondChild is not a constructor\n at new …Run Code Online (Sandbox Code Playgroud)