JQuery best practice, using $(document).ready inside an IIFE?

前端 未结 4 1423
我在风中等你
我在风中等你 2020-12-07 16:40

I am looking at a piece of code:

(function($) {    
   // other code here    
 $(document).ready(function() {   
    // other code here    
  });    
})(jQue         


        
4条回答
  •  执念已碎
    2020-12-07 17:42

    IIFE needs to create a one more scope. If you remove IIFE and $ will no be defined (ie jQuery.noConflict()) - you will get an error. jQuery will defined everywhere the javascript file with library was loaded.

    So it's not jQuery best practise, it's a javascript best practise.

提交回复
热议问题