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();
6
  • I keep seeing a lot of questions tagged javascript + typescript, even when typescript is not really used. Is microsoft polluting learners?
    – GrafiCode
    Commented Sep 17, 2022 at 11:08
  • Please create a variable and assign an array of classes to this variable Commented Sep 17, 2022 at 11:10
  • No, just in my project using both and for me doesn't matter on with one lang we will discuss it. Commented Sep 17, 2022 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. Commented Sep 17, 2022 at 11:15
  • 1
    This parser might help you: esprima.org please check this answer: stackoverflow.com/a/25473571/5334486
    – GrafiCode
    Commented Sep 17, 2022 at 11:32

0

Browse other questions tagged or ask your own question.