check if a function exists with its name in a string?

后端 未结 3 1500
情话喂你
情话喂你 2020-12-15 15:45

I create functions in Javascript dynamically. Sometimes I need to check if a certain function is actually already created.

I have the name of the function a

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-15 16:07

    You can use eval:

    if ( eval("typeof stringFunction === 'function'") ){ /*whatever*/ }
    

提交回复
热议问题