Weird JavaScript Syntax __java

Source: Internet
Author: User

A few days ago a colleague asked me how the following JavaScript code understood:

(function ($) {}) (jQuery);

In fact, it is relatively simple to understand several concepts:

1, (), in JavaScript () indicates the execution of a method, such as:

function X () {

Alert ("xxx");

}

var a = x; No call, A is a function

var a = x (); The function is called, and the value of a is the result of the call: undefined

2, jquery is a jquery object, which means that when calling a function, passing in a parameter is a jquery object.

There's nothing to talk about here.

3, (function ($) {}) This is an anonymous function, the formal parameter is $, parentheses are necessary.

This is understood, the upper-style equivalent

var f = function ($) {};

f (jQuery);

Now look at, that is not simple nor strange ...

Related Article

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.