Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
Given a class name, how do I get its class object?

After I have evaled: class myclass{}, I want to get that class object, given its name. When you eval: function myfn(){} You can do: window.myfn and globalThis["myfn"] to get the function object. But for getting the class object, this doesn't work. I can do: eval("myclass") to get the class object, but many stackoverflow responders don't like using eval. Is there another way to do it?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use the Function() constructor to create a new class and assign that value to a global variable:

const className = 'myclass';

window[className] = new Function(`class ${className}{}; return ${className}`)()

console.log(myclass)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!