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