Jquery2.6 source code learning

Source: Internet
Author: User

The following is a summary of jquery source code learning to be improved...
1. The overall structure of the JS file is as follows: (function () {}) (... omitted row 3548); this should be equivalent to an eval function.

2. Each $ ("") generates a jquery object. The constructor is as follows:
VaR jquery = Window. jquery = Window. $ =
Function (selector, context)
{
Return new jquery. FN. INIT (selector, context );
}

3. jquery. fn = jquery. Prototype = {...}
Assign a value to the prototype of the jquery class. It shares the object with jquery. fn.
Jquery. FN. init. Prototype = jquery. FN; then set the prototype of jquery. FN. init to jquery. FN, that is, jquery. prototype.
The constructor (return New jquery. FN. INIT (selector, context);) returns a jquery object.

4. jquery. Extend = jquery. FN. Extend = function () {...} defines extend. When calling this method, copy the members of the parameter object
In the jquery class. jquery [name] = objet [name];


5. The jquery. Each (object, callback, argS) function is added to the jquery object through the extend method. The call method is as follows:
Jquery. Each ({
Parent: function (ELEM) {return ELEM. parentnode ;},
Parents: function (ELEM) {return jquery. dir (ELEM, "parentnode ");},
Next: function (ELEM) {return jquery. Nth (ELEM, 2, "nextsibling ");},
}, Function (name, FN ){
Jquery. FN [name] = function (selector ){
VaR ret = jquery. Map (this, FN );

If (selector & typeof selector = "string ")
Ret = jquery. multifilter (selector, RET );

Return this. pushstack (jquery. Unique (RET ));
};
});

In jquery. Each, the key is to use callback. Apply (object [name], argS) to make the object [name] object (
For example, function (ELEM) {return ELEM. parentnode;}) Execution Method
Function (name, FN ){
Jquery. FN [name] = function (selector ){
VaR ret = jquery. Map (this, FN );

If (selector & typeof selector = "string ")
Ret = jquery. multifilter (selector, RET );

Return this. pushstack (jquery. Unique (RET ));
};
} To copy the member (method) in the object to jquery. FN, that is, jquery. prototype, so as to increase the method on the jquery 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.