JQuery aims to Write Less and Do More. Its development style of JavaScript is not as invasive as YUI, and of course it is not as large as Dojo and YUI. It greatly simplifies the daily development of JavaScript, mainly the operation of DOM elements (as can be seen from the name Query ). Another major task is browser compatibility that every front-end developer must face. JQuery is compatible with most mainstream browsers, starting from Internet Explorer 6 to modern browsers such as Firefox and Chrome. In addition to a small part of the core code, jQuery is a loose function with high scalability. There are thousands of jQuery plug-ins on the http://plugins.jquery.com, and almost all the functions you need have the corresponding jQuery plug-ins, and there are more than one.
The header of jQuery code is the License declaration. GPLv2 and MIT protocols are used. The jQuery declaration is another project declaration: Sizzle. This is another open-source project developed by jQuery and released under MIT, BSD, and GPL. It is an independent selector implementation (pure-JavaScript CSS selector engine) and can be used independently. Its compression version is only a little more than 3 kb, and it is called the most efficient selector implementation. JQuery has replaced the original selector Implementation With Sizzle Since 1.3.
There are a lot of () and {} in JS Code. Here we use Vim to read, because the % command can quickly find matching brackets.
Overall code structure and variables
JQuery's code is an anonymous function call:
Copy codeThe Code is as follows:
(Function (window, undefined ){
//...
}) (Window );
This is to avoid contamination of global objects and facilitate the management of execution context. This technique is often seen in JS Code and is also common in jQuery code. For example, when jQuery and other JS libraries are used simultaneously, the $ symbol may already be used. To still use the $ symbol:
Copy codeThe Code is as follows:
(Function ($ ){
// $ ("...")... Use as usual $
}) (JQuery );
Input a real jQuery object here.
The real implementation section is as follows: $, the declaration of the jQuery object. The two most basic members are also listed:
Copy codeThe Code is as follows:
Var jQuery = (function (){
Var jQuery = function (selector, context ){
// Real initialization Function
Return new jQuery. fn. init (selector, context, rootjQuery );
},
// A large number of variable declarations
// Fn is the main function implementation point and the starting point of the jQuery plug-in. It is actually a JS prototype.
JQuery. fn = jQuery. prototype = {
};
// A function used to expand an object. It can dynamically add members to the object. The extend function will be used to add members to jQuery later.
JQuery. extend = jQuery. fn. extend = function (){
};
//...
Return jQuery;
})();
JQuery objects are core objects, all $ (...) all the results are jQuery objects. Except for a small number of Utility functions directly implemented under jQuery, most functions are added to jQuery objects using the extend method.