A simple analysis of the difference between jquery (function () {}) and (function () {}) (jquery) _jquery

Source: Internet
Author: User

jquery is an excellent javascrīpt framework. Let's now discuss the functions that are executed after two pages are loaded in Jquery.

$ (document). Ready (function () {
Write your code here ...
); Code that runs when the DOM load completes

Can be written by Jane

JQuery (function () {
});

(function ($) {}) What do you mean by (jQuery)?
(function () {
}) (JQuery);

It actually executes the () (para) anonymous method, except that it passes the jquery object.

Equivalent
function AA ($) {}
AA (JQuery)

is an idiomatic way to initialize a jquery object.

The popular point is that the page is loaded after the completion of the code you need to execute.
But this thing, sometimes will make the page beat, a lot of jquery plug-ins are loaded after the completion of the change in style, the page will have the feeling of beating or flashing. For example Ui.tab this plugin, page element a lot, all show out, it just form tab, very Dizzy said

(Funtion () {}) (); Execute the function immediately; the equivalent of declaring a function, calling directly after the declaration is finished;

If the parameter is as follows:
(Funtion (str) {alert (str)}) ("Output")) ; equivalent to: funtion outputfun (str) {alert (str);};o Utputfun ("Output");

JQuery (function () {}), the code that holds the operation Dom object, and the DOM object already exists when the code is executed. cannot be used to store the development plug-in code, because the jquery object is not passed, the external through the Jquery.method can not call the method (function).
(function () {}) (jQuery); code that holds the development plug-in, the DOM does not necessarily exist when the code is executed, so be careful with the code that performs the DOM operation directly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.