0

For example, when I define two classes inside a function, can I somehow get a list of classes that were declared on the same level?

function a(){
 
   class Class1{ }

   class Class2{ }

   console.log(/*something*/ ); //result: Class1, Class2


}

a();
  • I keep seeing a lot of questions tagged javascript + typescript, even when typescript is not really used. Is microsoft polluting learners? – GrafiCode Sep 17 '22 at 11:08
  • Please create a variable and assign an array of classes to this variable – captain-yossarian from Ukraine Sep 17 '22 at 11:10
  • No, just in my project using both and for me doesn't matter on with one lang we will discuss it. – Yurii Panasenko Sep 17 '22 at 11:12
  • It's the main question, how can I get the list. Based only on the scope. Without any arrays/object etc. (as a source code) that will contain enumeration of all classes. – Yurii Panasenko Sep 17 '22 at 11:15
  • there is no way to do it clean or natively. the only **horrible** option is to get the string representation of `a()` function (`a.toString()`) and then parse that string. Not really a good solution though. – GrafiCode Sep 17 '22 at 11:25
  • 1
    This parser might help you: https://esprima.org/ please check this answer: https://stackoverflow.com/a/25473571/5334486 – GrafiCode Sep 17 '22 at 11:32

0 Answers0