I have a string in JSON format that tells me information about what function to call and it's parameters and I'm trying to figure out how to send those parameters to the function.
var obj = JSON.parse("{'jFunc':'UpdateStat', 'args':['health','100']}")
var fn = window[obj.jFunc];
if(typeof fn == 'function'){
fn(); // how do I pass the args correctly here, in order
}
function UpdateStat(statName, statValue){
}
Note that there could be any number of args. In this example I know I could pass args[0] and args[1] but this is just an example to a generic process where we don't know the number of args that may exist.
I also don't want to pass the args array and have the function handle breaking it out. I'd prefer the final function being called be as normal as possible so as to not worry about those details.