How to check if a function is already defined?

后端 未结 10 1564
后悔当初
后悔当初 2021-01-01 08:52

How to check if a function is already defined ?

10条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-01 09:49

    Like so:

    if (typeof myFunc != 'undefined') {
        // Assign myFunc
    }
    

    Don't just test it against undefined, which is not a constant and can be reassigned.

提交回复
热议问题