The method of _jquery of jquery object initialization

Source: Internet
Author: User

The methods of the jquery object initialization include:

1.$ (DomElement)
2.$ (' 3.$ (function () {}); <===> $ (document). Ready (function () {});
4.$ ({selector: '. class ', Context:context}) <===> $ ('. class ', context)

Copy Code code as follows:

Jquery.fn = Jquery.prototype = {
Constructor:jquery,
Init:function (selector, context, rootjquery) {
var match, Elem, ret, doc;
Handle $ (""), $ (null), $ (undefined), $ (false), and return directly to this
if (!selector) {
return this;
}
When the parameter selector is a DOM node, the context is placed as selector
if (Selector.nodetype) {
This.context = this[0] = selector;
This.length = 1;
return this;
}
Handle HTML Strings
When the passed-in selector argument is a string, the
if (typeof selector = = "string") {
if (Selector.charat (0) = = "<" && Selector.charat (selector.length-1) = = ">" && selector.length >= 3) {
Assume that strings so start and end with <> are HTML and skip the Regex check
Match = [NULL, selector, NULL];
} else {
Match = rquickexpr.exec (selector);
}
Match HTML or make sure no, specified for #id
if (Match && (match[1] | | |!context)) {
HANDLE: $ (HTML)-> $ (array)
if (Match[1]) {
Context = Context instanceof JQuery? CONTEXT[0]: Context;
Doc = (context && Context.nodetype context.ownerdocument | | context:document);
Scripts is true for Back-compat
selector = jquery.parsehtml (match[1], doc, true);
if (Rsingletag.test (match[1]) && jquery.isplainobject (context)) {
This.attr.call (selector, context, true);
}
Return Jquery.merge (this, selector);
HANDLE: $ (#id)
} else {
Elem = document.getElementById (match[2]);
Check parentnode to catch when Blackberry 4.6 returns
Nodes that are no longer in the document #6963
if (Elem && elem.parentnode) {
Handle the case where IE/Opera return items
By name instead of ID
if (elem.id!== match[2]) {
return Rootjquery.find (selector);
}
Otherwise, we inject the element directly into the JQuery object
This.length = 1;
This[0] = Elem;
}
This.context = document;
This.selector = selector;
return this;
}
HANDLE: $ (expr, $ (...))
else if (!context | | context.jquery) {
Return (Context | | rootjquery)-FIND (selector);
HANDLE: $ (expr, context)
(which is just equivalent to: $ (context). Find (expr)
} else {
Return this.constructor, find (selector);
}
HANDLE: $ (function)
Shortcut for document ready
When selector is a function, it is equivalent to $ (document). Ready (selector);
else if (jquery.isfunction (selector)) {
return Rootjquery.ready (selector);
}
Resets properties selector and context when the selector parameter is {selector: ' #id ', context:document}, and so on
if (selector.selector!== undefined) {
This.selector = Selector.selector;
This.context = Selector.context;
}
return Jquery.makearray (selector, this);
}
};

The above is the entire content of this article, I hope you can enjoy.

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.