10. jquery source code analysis. Map ()

Source: Internet
Author: User

763 rows: three parameters.
Elems: The array or object to be traversed.
Callback: The callback function executes on each element of an array or on each property of an object. Two arguments passed in when executing: array element, element subscript, or property name, property value.
ARG: Only used within jquery. If the call to $.map () is passed to the parameter arg, the parameter is passed to the callback function callback;
The code for line 768 is a bit long and modifies its number.
Isarray=elems instanceof JQuery
|| Length!=undefined && typeof length=== "number"
&& ((Length>0&&elems[0] && elems[length-1])
|| Length===0
|| Jquery.isarray (Elems)
);
Parse the above code.
If Elems is a jquery object, then isarray=true;
If Elem.length is numeric and satisfies one of the conditions, Isarray=true:
Length>0 and Elems[0] is true, and elems[length-1] is true.
Length==0
Elems is an array.
771~778 rows, for arrays or class array objects (Document.getelementbyclassname ("MyClass")), the callback is executed for each element through a for loop subscript, if the return value of callback is not NULL , the return value is placed in the array ret.
781~789 rows, for an object, the property name is traversed through the for-in loop, the callback is executed for each property, the passed parameter is the property value, the key value, and Arg. If the return value of callback is not NULL, the return value is placed in the RET array.

792 rows: Call Concat () on an empty array, merge ret into an empty array, and return a new array. (Concat () is used to merge arrays.)

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.