javascript - Concatenation function name in js -


Is there a way to include the JS function name? Now I have this:

  switch (play id) {case "11": play 11 (); break; Case "22": Play 22 (); break; Case "33": play33 (); break; Case "44": Play 44 (); break; Default: Break; }   

And I want to do something like this:

  var function = "play" + playId + "()";   

And call it .. What is the best way if possible?


Solution:

What did I do with the help of thefourtheye and xdazz :

  var playFunction = window ["play" + playId]; PlayFunction ();    

If these functions are defined in global scope, you can obtain them globally Object can:

  var foo = window ["play" + taskId];   

Otherwise you can put them together in one object as if another answer has been suggested.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -