Rookie of the jquery source learning notes (iii)

Source: Internet
Author: User

1 function (callback, args) {  2     return Jquery.each (This, callback, args); 3 },     

Each: This invokes the Jquery.each method, which iterates through the current collection. Let's look at the Jquery.each method first:

//args is an arrayeachfunction(obj, callback, args) {varvalue, I= 0, Length=Obj.length, IsArray=isarraylike (obj); if(args) {if(IsArray) {//if the object being traversed is an array then the element is traversed by the subscript             for(; i < length; i++) {Value=callback.apply (Obj[i], args); if(Value = = =false) {                     Break; }            }        } Else {            //if the target of the traversal is not an array, iterate through the object members by enumerating the objects             for(Iinchobj) {Value=callback.apply (Obj[i], args); if(Value = = =false) {                     Break; }            }        }    //A Special, fast, case for the most common use of each    //if no args array is passed in}Else {        if(IsArray) {//if the object being traversed is an array then the element is traversed by the subscript             for(; i < length; i++) {Value=Callback.call (Obj[i], I, obj[i]); if(Value = = =false) {                     Break; }            }        } Else {            //if the target of the traversal is not an array, iterate through the object members by enumerating the objects             for(Iinchobj) {Value=Callback.call (Obj[i], I, obj[i]); if(Value = = =false) {                     Break; }            }        }    }    returnobj;},

The entire method structure is still very clear. In accordance with the args array there is no incoming divided into two branches, each branch in accordance with the traversal of the target is an array or an object is divided into two small branches. With the argument args, the callback method is called on each element that is traversed and passed in the parameter args. If there is no parameter args, then the callback actually passed in is the current sequence number I and the element itself, which is the invocation form we often use, such as $ (". Class"). each (function (i,e) {}).

In fact, I would like to emphasize that everyone should not just think that each method is only a regular use of each (function (i,e) {}) this form OH. In fact, each inside callback can take an array of parameters, but then remember that callback parameters can be not the number + current element ah.

Rookie of the jquery source learning notes (iii)

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.