JQuery selector code (7) -- elementMatcher function, jqueryelement

Source: Internet
Author: User

JQuery selector code (7) -- elementMatcher function, jqueryelement

To understand the Compile execution process of Sizzle, first of all, we need to find out the functions and key variables and roles of the involved subprograms. I will explain the Compile code of the jQuery-1.10.2 version one by one, hope to help you.

ElementMatcher (matchers)

1. Source Code

function elementMatcher(matchers) {return matchers.length > 1 ? function(elem, context, xml) {var i = matchers.length;while (i--) {if (!matchers[i](elem, context, xml)) {return false;}}return true;} : matchers[0];}

2. Functions

This function returns a function to determine whether the incoming elem matches the matching execution Function Array matchers. If not, false is returned; otherwise, true is returned.

If matchers has only one element, the element itself is returned. Otherwise, a new function is returned, that is, the function (elem, context, xml) function in the code.

The returned function is similar to context. filter (selectors). Of course, only true or false is returned, not the jQuery object.

3. Parameters

Matchers -- array. Each element is a non-pseudo-class matcher that executes the function. For example, in actual execution, div. map span: lt (10). The matching execution function of div and map will pass in the elementMatcher function as two elements of matchers to filter out whether the parent node of the span node meets the requirements.

4. Return Functions

4.1 If matchers has more than one element, the following function is returned:

function(elem, context, xml) {var i = matchers.length;while (i--) {if (!matchers[i](elem, context, xml)) {return false;}}return true;}
4.1.1 Functions

Call from the last matchers element to the first element to match whether the incoming elem node meets the requirements. true is returned if all the incoming elem nodes meet the requirements. Otherwise, false is returned.

4.1.2 Parameters

Elem-Single Node element to be checked.

Context -- the context node that executes the entire selector string matching. It is useless in most cases.

Xml: whether the current search object is an HTML or an XML document. If it is an HTML document, the xml parameter is false.

4.2 If matchers has only one element, the element itself is returned.

4.2.1 Functions

Check whether the imported elem matches the selector. If yes, true is returned. Otherwise, false is returned.

4.2.2 Parameters

Same as 4.1.2 parameter description.

JQuery selector code (1) -- Sizzle Method

JQuery selector code (2) -- select Method

JQuery selector code (3) -- tokenize Method

JQuery selector code (4) -- Expr. preFilter

JQuery selector Code Description (5) -- describes the tokenize parsing process

JQuery selector code (6) -- Sizzle selector matching Logic Analysis

JQuery selector code (7) -- elementMatcher Function

JQuery selector code (8) -- addCombinator Function

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.