const classes = {
Class1: class {
constructor(val) {
this.val = val;
}
method1() {
console.log('Class1', this.val);
}
},
Class2: class {
constructor(val1, val2) {
this.val1 = val1;
this.val2 = val2;
}
method2() {
console.log('Class2', this.val1, this.val2);
}
},
};
function createInstanceAddCallMethod(className, constructorParams, methodName) {
const instance = new classes[className](...constructorParams);
instance[methodName]();
}
createInstanceAddCallMethod('Class1', [ 69 ], 'method1');
createInstanceAddCallMethod('Class2', [ 187, 666 ], 'method2');