For many beginners it is difficult to understand what this means, and below I will introduce its corresponding role.
1, the front of the code, the semicolon, you can prevent multiple file compression merged to the last line of other files without a semicolon, resulting in a combined syntax error.
2, anonymous functions (function () {});: Because JavaScript execution expressions are from inside the parentheses to the outside, you can enforce the declared function with parentheses. Avoid variable conflicts within and outside the function.
3, $ argument: $ is a shorthand for jquery, many methods and class libraries also use $, here $ accept jquery objects, also to avoid the $ variable conflict, to ensure that plug-ins can run normally.
4, window, the document real parameter to accept window, Document object, window, document object is the global environment, and in the function of window, document is actually local variables, not the global window, The Document object. One of the benefits of this is that you can improve performance and reduce the query time of the scope chain, which is necessary if you need to call the window or document object multiple times in the body of the function to pass the window or document object as a parameter. Of course, if your plugin does not use these two objects, then you do not have to pass these two parameters.
5, finally left a undefined shape parameter, then this shape parameter is what use, look is a bit superfluous. Undefined in the older generation of browsers is not supported, direct use will be error, JS framework to consider compatibility, so add a formal parameter undefined
;(function ($, undefined) {}) (jQuery); The use and description of