What is the purpose of this? (function ($) { //function code here })(jQuery);

前端 未结 4 1127
遇见更好的自我
遇见更好的自我 2020-12-01 21:13

I am debugging someone else\'s JavaScript code and a majority of the code is wrapped like this:

(function ($) {
    //majority of code here...
})(jQuery);
         


        
4条回答
  •  孤街浪徒
    2020-12-01 21:47

    This structure is called JQuery Plugin, purpose of the plugins is to create a framework of any common task/function in your project, same-way you can extend your plugins according to your usage in different page or in same page. that way you can avoid repeating the same code everywhere.

    check it out http://docs.jquery.com/Plugins/Authoring

提交回复
热议问题