JQuery1.3.2 source code learning 1: $ what is it? What is jQuery?

Source: Internet
Author: User

JQuery1.3.2 source code learning

This source code uses the current jQuery 1.3.2 version. download time:. Click here to download

A function

1 /*!

2 * jQuery JavaScript Library v1.3.2

3 * http://jquery.com/

4 *

5 * Copyright (c) 2009 John Resig

6 * Dual licensed under the MIT and GPL licenses.

7 * http://docs.jquery.com/License

8 *

9 * Date: 17:34:21-0500 (Thu, 19 Feb 2009)

10 * Revision: 6246

11 */

12 (function (){

4376 })();

If you omit the content in the middle, you can see lines 12th to 4376. jQuery code can be simplified to the above Code.

That is, an anonymous function is defined and then executed.

Complete other definitions and operations in this anonymous function to avoid naming conflicts with other functions with the same name in the system. It is equivalent to a private scope.

What is $? What is jQuery?

13 var

14 // Will speed up references to window, and allows munging its name.

15 window = this,

16 // Will speed up references to undefined, and allows munging its

17 name.

18 undefined,

19 // Map over jQuery in case of overwrite

20 _ jQuery = window. jQuery,

21 // Map over the $ in case of overwrite

22 _ $ = window. $,

23

24 jQuery = window. jQuery = window. $ = function (selector, context ){

25 // The jQuery object is actually just the init constructor 'enabled'

26 return new jQuery. fn. init (selector, context );

27 },

Through this code, we can see that $. jQuery is a custom Member of the window object. This Member points to an anonymous function. In the future, you can use this function through $ or jQuery of the window object.

This function returns an object defined by the jQuery. fn. init function. The object obtained through jQuery is actually a jQuery. fn. the object created by the init function. fn. functions or attributes defined by the init prototype can be used by objects created by jQuery.

 

What is jQuery. fn?

35 jQuery. fn = jQuery. prototype = {

538 };

From row 35 to row 538, This is the definition of jQuery. fn. jQuery. fn is the prototype object of the function that jQuery points. Therefore, the functions defined on the jQuery prototype can be used through jQuery. fn.

The above jQuery. fn. init is a function on the jQuery function prototype object.

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.