10. jQuery source code analysis. map ()

Source: Internet
Author: User

Row 763: three parameters.
Elems: the array or object to be traversed.
Callback: the callback function is executed on each element or attribute of an array. Two parameters are input during execution: array element, element subscript, or attribute name and attribute value.
Arg: only used internally by jQuery. If $. map () is called to pass in the parameter arg, the parameter will be passed to the callback function callback;
The code of the first line is a little long. modify the number of lines.
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, isArray = true;
If elem. length is numeric and one of the conditions is met, isArray = true:
Length> 0, elems [0] is true, and elems [length-1] is true.
Length = 0
Elems is an array.
771 ~ Row 3: For an array or a class array object (document. getElementByClassName ("myClass"), callback is executed for each element through the for loop subscript. If the return value of callback is not null, the returned value is placed in the array ret.
781 ~ Row 3: for objects, the property name is traversed through the for-in loop and callback is executed for each attribute. The input parameter is the property value, key value, arg. if the return value of callback is not null, the return value is placed in the ret array.

Row 792: 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.