I am trying to add and invoke function dynamically. For that, below is the code
filed = [];
function fileIt(thing) {
// Dynamically call the file method of whatever
thing.addIt();
// Mark as filed
filed.push(thing);
}
function repType1(name) {
this.name = name;
}
repType1.prototype.addIt = function () {
//Business Logic will go here
console.log("Heloo From repType1");
}
function repType2(name) {
this.name = name;
}
repType2.prototype.addIt = function () {
//Business Logic will go here
console.log("Heloo From repType2");
}
let rep1 = new repType1("repType1");
fileIt(rep1);
I am able to call function using let rep1 = new repType1("repType1"); for repType1but i need to do it dynamically so that same line of code can call my other function 'repType2' as well. I have the function parameter value as string for example: "repType1", "repType2", etc. How to do it?