JavaScript dynamic function name

前端 未结 4 1392
忘了有多久
忘了有多久 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:37

    If you want to store it as a function, pass the function directly. Otherwise, if you just want to store it as a string, then you can use the quotes.

    Change:

    cr['cmd1'] ='foo';
    

    To:

    cr['cmd1'] = foo;
    

提交回复
热议问题