Home Instantiate class object with variable class name in nodejs
Reply: 0

Instantiate class object with variable class name in nodejs

user681
1#
user681 Published in August 15, 2018, 8:44 pm

Is there a way in nodejs to instantiate class object with variable class name. I am trying the below snippet, it doesn't work though.

let className = "hello"; 
let object = new [className]();

EDITED I have multiple classes, out of those multiple classes I will get a subset(Array of String) as Input from another service and I have to call main function of those subset classes.

// Multiple classes = ["first", "second", ..............., "twenty"]; 

let subset_class_names = ["first", "three", "five"]; 

for (let aClass of subset_class_names) { 
    let object = new [aClass](); 
    object.main(); 
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305519 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO