Iv. jQuery source code parsing: jQuery. fn. init () Parameter Parsing

Source: Internet
Author: User

From return new jQuery. fn. init (selector, context, rootjQuery), we can see that
The selector and context parameters are transmitted when we call the jQuery method.
So what are the possibilities of selector and context.

 

For ~ The nine rows may be analyzed in detail.

If selector is a string, the first check is the html code or # id.
The if Statement of Row 3 starts with "<", ends with ">", and the length is greater than or equal to 3. assume that this is an HTML clip. Here we only assume that it is not necessarily the html code of Hefei. for example, "<div> <guofsfsdfd> ";
Else In line 1: indicates that the Code is not html. In this case, use a regular expression to detect the code.

I am not familiar with regular expressions, but I can understand them roughly. The matching result is html and id. The matching result is assigned to match.

After analyzing the selector and context parameters, do we forget the rootjQuery parameter.
This parameter is defined internally by jQuery, not manually passed in from the outside.
We can probably guess the approximate situation of this parameter from the name: the root jQuery object.
See the source code definition:


Under what circumstances will the program use this parameter?
1. When search for document. getElementById () fails,


2. selector is a function:


3. selector is a selector expression and context is not specified;

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.