-1

I have a function pool:

var func0 = function(a0){...}
var func1 = function(a0, a1){..}
var func2 = function(a0, a1, a3){...}

Now I got the function name and a arguments array:

var name = 'func1';
var params = [arg0, arg1];

Name is a dynamic string so I can't write like:

func1(arg0, arg1);

Is there any way can let the params passed into the function like reflection in java?

Note without using "arguments":

func(){ console.log(arguments[0]);}

@Felix Kling this is not a duplication, my question is how to pass variable parameters, and i know the way obj[name] but this doesn't help my question.

My question is how to convert params[arg0, arg1] into func(arg0, arg1), not func(params) and not func(){arguments[0]...argument[1]...}

FredSuvn
  • 1,869
  • 2
  • 12
  • 19

1 Answers1

0

Use the eval function, like this

eval(name+"("+params[0]+","+params[1]+")");
Jay Ghosh
  • 674
  • 6
  • 24