Je suis très nouveau à la programmation js. Je travaille pour le développement de tests. J'ai besoin d'appeler une fonction js avec le nom qui est stocker sur un fichier. Par exemple, j'ai deux fichiers,javascript appeler une méthode avec un nom stocké sur une variable
file1.sah
//sah is sahi extension but internally the file has javascript code only
function test(){
this.var1 = 100;
this.logFunc = function(a,b,c){
console.log(a + b + c + this.var1);
}
}
file2.sah
include file1.js //file1.js module is referenced
var obj = new test();
var $method = "logFunc";
var $params = {"a" : 1, "b" : 2, "c" : 3};
//wanted to call the method "test" from file1 and pass all arguments as like key & value pair in object
//I cannot use window objects here
eval($method).apply(obj, $params);
//eval works but I couldn't pass the object params I have. For simplicity I //have initialised params in this file. In my real case it will come from a
//different file and I will not know the keys information in the object
Le nom de la méthode est 'logFunc', pas' test'. – Barmar