JQuery scripts: function (window, document, undefined) vs; (function ($, window, document, undefined)

I saw some jQuery scripts embedded in web pages that open with

(function(window, document, undefined){...

or

;(function ( $, window, document, undefined ) {...

I believe that it ;can be there if the script is connected to other files and there is no closing bracket, it ;stops the minifier from deleting the first lines of code, but I'm not sure.

What happens to the two options I posted? Why do people open their code like this, why doesn't the first example have a dollar sign?

+5
source share
1 answer

These are wrappers for creating an environment for a script that is as predictable as possible.

script , , :

(function($, window, document, undefined){
 ...
})(jQuery, window, document);

jQuery, $, . ( .)

, undefined . , undefined, undefined undefined. , undefined Javascript, undefined , undefined. ( , undefined, undefined.)

, - script , .

+5

All Articles