JavaScript dynamic function name

前端 未结 4 1393
忘了有多久
忘了有多久 2021-01-27 15:19

I need to dynamically assign the name of a function to an element of an associative array. This is my attempt which does not work. The problem I am asking for help with is here

4条回答
  •  面向向阳花
    2021-01-27 15:45

    Access the functions using this syntax window[function_name]('para1');

    Your usage will be something like this

    var msg = window[cr['cmd1']](x);
    

提交回复
热议问题