JS Object-Oriented programming: use of two parentheses

Source: Internet
Author: User

In the process of viewing a lot of jquery, you often encounter two parentheses.

For example:

(function () {     alert ("Test 1");}) ();      (function () {     alert ("Test 3"); ());
In fact, this code defines an anonymous function and makes a call,

The equivalent of the following lines of code:

(function ListCommon2 () {     alert ("Test 1");}) ();      (function ListCommon3 () {     alert ("Test 3"); ());

Further rewriting for our normal use is to define the function first, in the call to:

function ListCommon2 () {     alert ("Test 1");};     ListCommon2 ();     function ListCommon3 () {     alert ("Test 3");};    

This is why we use a lot of jquery plugin libraries, although we did not call, just add in, but after the page has finished loading, still do a lot of operations, such as jquery Eiasyui has obviously modified the DOM, processing a lot of custom property tags.

How do I pass arguments to such functions? As with normal functions, for example:

  (function (text) {     alert (text);}) ("Test 1");      (function (text) {     alert (text);} ("Test 3"));



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.