if function does not exist write function - javascript

前端 未结 2 734
生来不讨喜
生来不讨喜 2020-12-30 05:34

In php I\'m writing the following


In javascript I wish to test if the

2条回答
  •  再見小時候
    2020-12-30 05:54

    Use a function expression, not a function declaration.

    if(typeof myfunction != 'function'){
       window.myfunction = function(){};
    }
    

    (I'm using window since your last paragraph suggests you want a global function)

提交回复
热议问题