Javascript self executing function “is not a function”

后端 未结 6 642
慢半拍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:56

    You may try declaring it this way:

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

    But this will reduce usage of this function into it's body

    Other way is to separate declaration from execution:

    var Init = function(){
        /*...*/
        },
        initResult = (function(){ return Init(); })();
    

提交回复
热议问题