jquery Source Line Analysis Learning 02 (Part one: some variables and functions of jquery)

Source: Internet
Author: User

The first time you try to use Office Word, much more convenient than online editing web page, but first use, some content is not familiar with, hope that the great God forgive ~

In the last article, the whole structure of jquery was combed, and the entire jquery structure was simplified, as follows:

1(function(){2(21, 94) defines a number of variables and functions jQuery =function(){};3(96, 283) to the JQ object, add some methods and properties4(285, 347) Inheritance method of EXTEND:JQ5(349, 817) Jquery.extend (): Extend some tool methods6(877, 2856) Sizzle: Implementation of complex selectors7(2880, 3042) Callbacks: Callback object: Unified management of Functions8(3043, 3183) Deferred: Deferred object: Unified management of Async9(3184, 3295) Support: function detectionTen(3308, 3652) data (): Cache One(3653, 3797) Queue (): Queue method: Execution Order Management A(3803, 4299) attr () prop () Val () addclass (), etc.: operation on element Properties -(4300, 5128) on () trigger (): Related methods for event operations -(5140, 6057DOM Action: Add delete get wrapper dom filter the(6058, 6620) CSS (): Style of the exercise -(6621, 7854) submitted data and Ajax (): Ajax () Load () Getjson ( ) -(7855, 8584Animate (): A method of motion -(8585, 8792) offset (): Method of position and size +(8804, 8821) JQ supports modular mode -(8826) window.jquery = window.$ =JQuery; +})();

This time, we will start a progressive decomposition of the jquery source code.

Start with a comment from the beginning

The starting note contains the following: jquery version, jquery official website, sizzle website, jquery copyright information, software license and update time

Then we start the anonymous self-executing function

1 (function(window,undefined) {}) (window);

First look at the role of the following:

The window parameter has two functions: first, in the code execution process, some methods, properties are connected through the tree structure, the incoming window parameter is equivalent to the program indicated a search direction, so as to improve the efficiency of the program lookup; second, pass in the window parameter, This facilitates later for code compression, during the compression process, the window parameter becomes a compression program automatically generated variable code, so it is easy to compress.

The undefined parameter has a role: because values such as undefined can easily be tampered with in such a large amount of programs, the undefined is passed into the parameters of the self-executing anonymous function to prevent inadvertent tampering during the procedure.

In the following comments, there is a section on use strict, here to explain: In strict mode, code needs special specifications, a little nonstandard will be error, it is recommended not to use. As an example:

We are normal when declaring an assignment variable, the following notation is correct:

1 a=10;

But in use strict mode will be error, must be

1 var a=10;

For example, in the case of octal numbers, we can define octal numbers in general:

1  var a=010;

However, in use strict mode, this octal number is not supported, will be error.

Next, starting with the (23) line, we define some variables and some functions

  rootjquery: This variable represents the root directory of jquery, in line (866)

1 rootjquery=jquery (document);

Define this variable to facilitate the maintenance of late code

readylist: This variable is related to DOM loading, and a variable related to Ready (FN)

core_strundefined=typeof undefined, undefined in string form

In a==undefined and typeof a== ' undefined ', the new version of the browser is no different, but the old version of the browser may not be able to discriminate, so here, the use of this although difficult to write a little but the way of preservation.

location=window.location; Store the Location object under window separately

document=window.document; Separate the Document object under window to define the storage

docelem=document.documentelement; To define the Document.element object separately for storage

Next

  _jquery=window.jquery,

_$=window.$,

These two variables are used to prevent conflicts with other programs, many programs will be exposed to the interface when the use of the $ symbol, so it is unavoidable conflict, here is to resolve the conflict.

  class2type={}

$.type (), which is used to determine the type of

Core_deletedids=[]

This variable is related to cached data and is generally useful in older versions

core_version= ' 2.0.3 '

This variable is the version number of this version of jquery

(52,58) core_concat= ...

Some of the core methods of storage, which include the Concat,push,slice,indexof,tostring,hasown,trim method

Next we define the jquery function

Jquery=function () {}

$ () = JQuery ()

Here's an analysis of this structure

1 jquery=function(selector,context) {2         returnnew  JQuery.fn.init (selector,context,rootjquery); 3 }

But in line (283), the following code appears

1 (283) Jquery.fn.init.prototype=jquery.fn;

The prototype of the Jquery.fn initialization method is Jquery.fn

When writing object-oriented objects in general

1 function Aaa () {} 2 aaa.prototype.init=function() {}; 3 aaa.prototype.css=function() {};

When called:

var a1=New  Aaa (); A1.init (); A1.css ();

We need to call the initialization method manually before we call other methods;

In jquery, object-oriented is like this:

1  function JQuery () {2      return New jQuery.prototype.init (); 3 }4  jquery.prototype.init=function() {}; 5  jquery.prototype.css=function() {}; 6  Jquery.prototype.init.prototype=jquery.prototype;

When called:

1  var a2=New  jQuery (); 2  A2.css ();

There is no need to call the initialization method again, the initialization method is already called at the time of the new object.

Next, we define some matching regular

  (core_pnum=) ... This matches the number's regular

core_rnotwhite= ... This is a matching word.

rquickexpr= ... Match prevents XSS injection, prevents input boxes from entering a virus, like <P>AAA or #div

rsingletag= ... Match independent empty tags, such as <p></p> <div></div> in this form

rmsprefix= ... IE browser prefix

rdashalpha= ... Turn Case-L turn into L this form

Next

1 fcamelcase=function(all,letter) {2         return  Letter.touppercase (); 3 }

callback function of the turning hump naming method

1 completed=function() {2         document.removeeventlistener (' domcontentloaded ', completed,false); 3         Window.removeeventlistener (' Load ', completed,false); 4         Jquery.ready (); 5 }

callback function triggered after the DOM is loaded successfully

Thank you for your busy schedule to read my blog ~ ~

Click to download jquery code file

Previous Portal: jquery source Progressive Analysis Learning (jquery framework Simplification)

jquery Source Line Analysis Learning 02 (Part one: some variables and functions of jquery)

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.