Best practices for declaring functions inside jquery ready function

前端 未结 3 1497
迷失自我
迷失自我 2020-12-24 06:08

I haven\'t found a good reference for declaring my own functions inside the

jquery.ready(function(){});

I want to declare them so they

3条回答
  •  时光说笑
    2020-12-24 06:58

    I believe that you would be okay just declaring the function inside the ready() closure, but here you can be a bit more explicit about the local scoping:

    jQuery.ready(function() {
    
         var myFunc = function() {
    
               // do some stuff here
    
         };
    
         myFunc();
    
    
    });
    

提交回复
热议问题