jquery Selector code detailed (vii)--elementmatcher function

Source: Internet
Author: User

To read sizzle compile implementation process, the first need to understand the various sub-programs involved in the function and key variables and role, I will jQuery-1.10.2 version of the compile code to explain, hope to give everyone help.

Elementmatcher (matchers)

1. Source Code

function Elementmatcher (matchers) {return matchers.length > 1? function (elem, context, XML) {var i = Matchers.length;w Hile (i--) {if (!matchers[i] (elem, context, XML)) {return false;}} return true;} : Matchers[0];}

2. function

The function returns a function that determines whether the incoming elem conforms to the matching execution function array matchers, or returns True if it does not satisfy the return false.

if matchers has only one element, the element itself is returned, otherwise a new function is returned-that is, function (Elem, context, XML) in the code.

The return function effect is somewhat similar to context.filter (selectors), and of course, its result simply returns TRUE or FALSE, not the jquery object.

3. Parameters

The matchers--array, each of which is a non-pseudo-class matching execution function. For example: During the actual execution, Div.map span:lt (10), where the matching execution function for Div and map will pass in the Elementmatcher function as a matchers two element to filter whether the parent node of the span node satisfies the requirement.

4. Return function

4.1 If more than 1 elements are matchers, 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 function

The last element from matchers to the first element is called sequentially to match whether the incoming Elem node satisfies the requirement, all satisfies the return true, otherwise returns false.

4.1.2 Parameters

elem--the individual node element to be inspected.

context--executes a context node that matches the entire selector string, and most of the time it has no purpose.

xml--whether the current search object is HTML or an XML document, and if HTML, the XML parameter is false.

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

4.2.1 function

Checks if the incoming Elem matches the selector and returns false if the match returns true.

4.2.2 Parameters

The same 4.1.2 parameter description.

jquery Selector code detailed (a)--sizzle method

jquery Selector code in detail (ii)--select method

jquery Selector code in detail (iii)--tokenize method

jquery Selector code in detail (iv)--expr.prefilter

jquery Selector code in detail (v)--example illustrates the parsing process of tokenize

jquery Selector code detailed (vi)--sizzle selector matching logic analysis

jquery Selector code detailed (vii)--elementmatcher function

jquery Selector code detailed (vii)--elementmatcher 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.