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.