Javascript self executing function “is not a function”

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

    In order for Init to execute as a function, your code within the self-executing function must return a function, and the only reason to do this is if you need to construct a specific function dynamically dependent upon some data states:

    var Init = (function() {
    
        // some code
    
        return function () {
            // some dynamic code dependent upon your previous code
        };
    
    }());
    

提交回复
热议问题