11. jquery source code parsing. Pushstack ()

Source: Internet
Author: User

pushstack () Gu Mingsi means to add something like buyers, now look at how he adds things.
Create an empty jquery object, and then put the DOM element collection into this jquery object,
and retains a reference to the current jquery object.
Pushstack is one of the core methods that provide support for the following methods:
jquery object traversal:. EQ (), First (),. Last (),. Slice (),. map ();
Dom Lookup, filtering:. Find (),. not (),. filter (),. closest (),. Add (),. andself ().
DOM traversal:. Parent (),. Parents (), Parentuntil (),. Next (),. Prev (),. Nextall (),. Prevall (),
. Nextuntil (),. Prevuntil (), siblings (),. Children (),. Contents ().
dom insertion: $.before (), $.after (), $.replacewith (),. append (),. Prepent (),. Brfore (),. After (),. replacewith ().

241 Line: Define method Pushstack (Elems,name,selector).
Elems: An array of elements (or a collection of similar arrays) ready to be put into a new jquery object.
Name: The jquery method name that produces an array of elements elems, such as Eq,find,after,filter ...
Selector: Parameters passed to the jquery method to correct the prototype properties. Selector.

243 rows: Thisconstructor is the execution of the jquery constructor. Parentheses. Represents the execution qualification constructor.
then RET is a jquery object. But this jquery object is not referenced by DOM elements,
only the members that jquery itself has.
245~250: The parameter elems is merged into the new jquery object.
If Elems is an array, borrow push to insert; otherwise call method Jquery.merge () merge.
253 Line: Add the property Prevobject () to the new jquery object, and point to the current jquery object,
formed a chain of buyers. Therefore, Pushstack () can also be understood as building a new jquery object into the stack,
The new object is at the top of the stack.
255 Line: Specifies the context for this new jquery. This.context either the specified ancestor Dom node, or the default Rootjquery, as stated in the previous section, is not mentioned.
257~261 The main line is to give the RET to specify the selector. That is, on the basis of the incoming parameter selector,
selector as a new object RET after the transformation is completed.
264 rows: Returns the new jquery object.

311 rows: Prevobject is the reference that is added in the call to Pushstack, which means that there is no action on the stack, and the reference is empty;
At this point, an empty jquery object is built and returned by the constructor property.
The. End () method and the. Pushstack () method are the opposite principle.

The. Pushstack () is used in the stack, and end () is used for the buyers.

1 $ (". Guo"). Find (". Yan"). CSS ("Color", "red")  // use Find () into the stack (find called Pushstack ())  2         . End ()          // will find (". Yan") Out buyers 3         . Find (". Si");   // continue looking for $ (". Guo"): Find (". Si")

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.