in JavaScript $ (function () {...}) Is the classic use of jQuery, equivalent to $ (document). Ready (function () {...}), that is, after the page has finished loading to execute a function, if you want to manipulate the DOM in the function, it will be more secure after the page load is completed. So this is a common way to use JQuery.
$ (document). The code in Ready () is executed when the content of the page is loaded, and if the code is written directly into the script tag, when the page loads the script tag executes the code inside, At this point, if the code you are executing in the tag calls the code or DOM that is not currently loaded, the error will be, of course, if you put the script tag on the end of the page, then there is no problem, and ready effect.
$ (document). Ready (function () {}) can be simply written as $ (function () {});
Click paragraph backward, this paragraph is hidden:
If the $ (document). Ready (function () {}) is removed, the paragraph cannot be hidden:
But when you put the script at the end of the page, you can restore the hidden effect:
What is the role and usage of JavaScript (function () {})
It's okay with the object.
(function () {}) () represents an immediate method of executing an anonymous
Generally used to isolate from the outside world creating a closed-loop environment create a scope chain to avoid variable conflicts
(function () {
var A;
..........
}) ()
This article mainly introduces the $ (function () {}) in JavaScript, what is the difference between writing and writing, and I hope it will help you.