1. Why is the development plugin all written like this?
2, why should I wear jquery in? Is there a way to use jquery directly in the method or not?
1 First (function () {}) () This method creates an anonymous method and executes it immediately (function () {}) This is the parentheses following the anonymous method, which is called immediately.
Doing so creates a scope to ensure that internal variables do not conflict with external variables, such as jquery (the variables defined inside jquery).
2 (function ($) {}) (JQuery) The main function of this writing
or to ensure that jquery does not conflict with other class libraries or variables first is to ensure that the name of jquery is not a conflict with the external (jquery internal $ and jquery is the same thing has two names reason is afraid of $ Conflicts with other variable names two jQuery has a very small chance of collisions with other variables) and passing in anonymous objects, the anonymous object is named $ (actually the same as in jquery) and then you can be free in (function ($) {}) (jquery) Write your plugin without having to consider whether there is a conflict with the external variables
(function () {}) What is the function and purpose of (jQuery)?