Find all classes in a Javascript application that extend a base class

后端 未结 3 2023
陌清茗
陌清茗 2020-12-17 18:08

I have code like this

class Animal{}
class Dog extends Animal {}
class Cat extends Animal {}
class Donkey extends Animal {}

I want to look

3条回答
  •  不知归路
    2020-12-17 18:57

    It is not possible. You can never know e.g. about local classes defined inside some function, or privately in another module. And that's by design. It would be unmodular and break encapsulation.

    Also, the set of classes is not static in JavaScript. You can create new classes dynamically open-endedly.

    If you think you want such functionality then I strongly suggest you're holding it wrong. What are you trying to achieve?

提交回复
热议问题