0

So, if I had something like


class Event {// . . .}

class Children extends Event {// . . .}

class Second extends Event {// . . .}

Would there be any way to retrieve the Children and Second class objects, using the the parent class Event?

RayHutera
  • 11
  • 3
  • This feels like an [XY problem](https://en.wikipedia.org/wiki/XY_problem) where you are asking questions about a possible solution to some other problem without telling us what that other real problem is. We could probably help you better with the real problem since this possible solution is a dead-end. – jfriend00 Jan 27 '21 at 22:08
  • Does this answer your question? [Find all classes in a Javascript application that extend a base class](https://stackoverflow.com/questions/31618212/find-all-classes-in-a-javascript-application-that-extend-a-base-class) – Anderson Green Aug 23 '21 at 18:04

1 Answers1

1

Would there be any way to retrieve the Children and Second class objects, using the parent class Event?

No. Given just the code you show, there would not be any way to identify all subclasses of Event in plain Javascript. A parent object is not informed in any way when a subclass is defined, nor is any global catalog maintained. A subclass definition stands on its own and the fact that it subclasses/extends the Event class is not saved anywhere or registered anywhere. It's just information that is used when an instance of the subclass is actually created.

If you wanted to manually keep track of such a thing, you could create your own catalog of sub-classes and then make your code register everything in that catalog.

jfriend00
  • 683,504
  • 96
  • 985
  • 979