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?
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)