3

How can I find all subclasses (both immediate, as well as all descendants) of a given Javascript "class"? Note that Prototype (v1.6.0) supports this with "subclasses", but I am wondering about plain Javascript.

Lo HaBuyshan
  • 359
  • 2
  • 12
  • 2
    Javascript has no class, no style.. :( – jAndy Nov 26 '14 at 23:26
  • 1
    You can get the **prototype** of an Object using [`Object.getPrototypeOf`](http://msdn.microsoft.com/en-us/library/ie/ff877835(v=vs.94).aspx). Is that what you're referring to? – Sampson Nov 26 '14 at 23:28
  • 3
    Inheritance is a unidirectional relationship in JS. Unless you build something that handles your class generation and keeps track of subclasses, you can't do that (reliably). – Felix Kling Nov 26 '14 at 23:29
  • you build your own way, just like Prototype does. there's many ways to do it... – dandavis Nov 27 '14 at 00:08

1 Answers1

1

JavaScript (at least ES5 and below) has no concept of classes, it only knows prototypes, which have no idea who used them as "super" or "sub" construction. The Prototype library only knows these relations when you exclusively use its own class model on top of plain JS, simply tracking it as part of its extension API.

Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153