In my JavaScript code, I have a structure similar to a class where I'm trying to call a function from the same level using a passed-in function name.
Explaining this is a bit challenging, so let me illustrate with an example of what I'm aiming for.
function windowFactory(){
this.init = function(functionName,args[]){
SetTimeout(functionName(args),2000)
}
this.func1 = function(var1){
alert(var1);
}
this.func2 = function(var1, var2){
alert(var1+var2);
}
}
var win1 = new windowFactory();
win1.init("func1","hello");
var win2 = new windowFactory();
win2.init("func2","world","!");
This snippet demonstrates a simplified scenario, including syntax errors and typos.
Previously, I managed to achieve this by using Eval outside the class...
eval(funcName+"('"+darray[1]+"','"+darray[2]+"')");
It worked by moving it outside the Class and passing in placeholder values for parameters.