Home >Web Front-end >JS Tutorial >jQuery source code analysis notes (2) variable list_jquery

jQuery source code analysis notes (2) variable list_jquery

WBOY
WBOYOriginal
2016-05-16 18:06:161211browse

_jQuery = window.jQuery;
_$ = window.$;
These two variables are the only two global variables used by jQuery. In the jQuery.noConflict() function, these two variables will be restored.
For browser detection, jQuery uses checking UserAgent instead of feature detection.
rwebkit = /(webkit)[ /]([w.] )/,
ropera = /(opear)(?:.*version)?[ /](w )/,
rmsie = /(msie) ([w.] )/,
rmozilla = /(mozilla)(?:.*? rv:([w.] ))?/,
Initialization function init
jQuery pair The processing of JS objects is complicated, and the ultimate goal is to turn the result obtained by the jQuery selector into an object similar to an array. There are length, first, last, etc. Because $("...") selects some nodes from the DOM tree. However, $ also has many other functions, such as the commonly used $(function() { ... }) for initialization and execution after the page is loaded, and $("<..>...") to directly obtain a node. , used to append to the DOM tree.
The next step is a long init function starting from line 93. Init: function(selector, context, rootjQuery)
Steps:
1. Selector is an illegal parameter: empty character, null and undefined will return this directly. That is, a jQuery object with default properties.
2. Selector is DOMElement. That is, use native JS, such as getElementById, etc. to get the elements. Then, it is equivalent to wrapping the native DOM object with $. Place this element at the first position of the internal array and set length to 1. Then return.
3. Special optimization processing $("body"). That is the document.body element.
4. Selector is a string ending with . So suppose you want to create a new DOM element using a string. For example, $("

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn