The purpose of jQuery is Write Less, Do More. It's not as intrusive a JavaScript development style as YUI, and certainly not as massive as Dojo and YUI. It greatly simplifies the daily development work of JavaScript, mainly the operation of DOM elements (as can be seen from the name Query). Another major task that every front-end developer needs to face is browser compatibility. jQuery is compatible with most versions of all major browsers, starting from the evil IE6 to modern browsers such as Firefox and Chrome. Except for a small part of the core code, the rest of jQuery are loose functions and are highly extensible. There are thousands of jQuery plug-ins on http://plugins.jquery.com. Almost all the functions you need have corresponding jQuery plug-ins, and there is more than one.
The head of the jQuery code is the License statement. It adopts GPLv2 and MIT dual agreements. And under the jQuery declaration is the declaration of another project: Sizzle. This is another open source project from the author of jQuery, released under MIT, BSD and GPL. It is an independent selector implementation (pure-JavaScript CSS selector engine) and can be used independently. Its compressed version is only a little over 3KB and is known as the most efficient selector implementation. jQuery uses Sizzle instead of the original selector implementation starting from 1.3.
There are a lot of () and {} in the JS code. Vim is used to read it here, because the % command can quickly find matching brackets.
Overall code structure and variables
jQuery code as a whole is an anonymous function call:
Copy code The code is as follows:
(function (window, undefined) {
// ...
})( window);
Copy the code The code is as follows:
(function ($) {
// $("...")... Use $
})(jQuery) as usual;
Copy the code The code is as follows:
var jQuery = (function () {
var jQuery = function(selector, context) {
// The real initialization function
return new jQuery.fn.init(selector, context, rootjQuery);
},
// A lot of variable declarations
/ / fn is the main function implementation point and the starting point of the jQuery plug-in. It is actually the JS prototype
jQuery.fn = jQuery.prototype = {
};
// A function used to extend the object, which can be dynamically added to the object. Members. In the future, adding members to jQuery will be done using the extend function
jQuery.extend = jQuery.fn.extend = function() {
};
// ...
return jQuery;
})();
The above introduces the cult of personality jQuery source code analysis notes, including the content of the cult of personality. I hope it will be helpful to friends who are interested in PHP tutorials.