Javascript self executing function “is not a function”

后端 未结 6 537
慢半拍i
慢半拍i 2020-12-07 23:09

I have:

var Init = (function() {
   my js goes here
})();

And my js executes correctly when the page is loaded. I also have:



        
6条回答
  •  有刺的猬
    2020-12-07 23:34

    you could do as above, but you could also do

    function Init(){...}(); 
    

    There's nothing to stop you from having a named self-executing function. If you want to avoid having a function named Init, you can do as CD Sanchez suggested and assign it in the execution.

    The (); at the end makes it self executing. Wrapping the function in parentheses makes it anonymous. But it seems that you don't want it to be anonymous.

提交回复
热议问题