I am working with an array of object instances that have different types.
var instances: any = [];
instances["Object1"] = new TypeA();
instances["ObjectB"] = new TypeB();
Each type has its own methods with unique names and varying numbers of arguments. I am looking for a way to call these methods using a single function, passing data from the client to identify the method to call and provide necessary argument values.
function CallMethod(data){
let args = data.args; // it's an array
instances[data.objectId][data.methodId](??????);
}
Is there a way to automatically break down the args
array to pass its values as separate function arguments?
For example:
instances[data.objectId][data.methodId](args[0], args[1], ... args[n]);