JQuery Source Analysis Notes _php Tips

Source: Internet
Author: User
The purpose of jquery is to write less, do more. Its development style of JavaScript is less intrusive than Yui, of course, and not as powerful as dojo and Yui so large. It greatly simplifies the day-to-day development of JavaScript, primarily the operation of DOM elements (as can be seen from name query). Another major task is the browser compatibility that every front-end developer needs to face. jquery is compatible with most versions of all major browsers, starting with the evil IE6 until modern browsers such as Firefox,chrome. Aside from a small portion of the code that resides in the core, the rest of jquery is loosely functional and highly extensible. There are tens of thousands of jquery plug-ins on the http://plugins.jquery.com, and you need almost all the functionality of the jquery plugin, and more than one.
The head of the jquery code is the license declaration. The GPLV2 and MIT dual protocols are adopted. The statement of another project under the jquery declaration: Sizzle. This is another open source project by the jquery author, published under the MIT, BSD, and GPL. It is an independent selector implementation (Pure-javascript CSS selector engine) that can be used independently. Its compressed version is only a little more than 3KB, claiming the most efficient selector implementation. jquery began using sizzle in 1.3 instead of the original selector implementation.
JS Code has a large number of () and {}, where the VIM is used to read, because the% command can quickly find a matching bracket.
Code overall structure and variables
The code for jquery is generally an anonymous function call:
Copy Code code as follows:

(Function (window, undefined) {
// ...
}) (window);

This is to avoid polluting the global object, but also easy to manage the execution context. This technique is often seen in JS code and is common in jquery code. For example, when jquery and other JS libraries are used at the same time, the $ symbol may already be in use. In order to still use the $ symbol:
Copy Code code as follows:

(function ($) {
// $("...")... Use $ as usual
}) (JQuery);

Here, pass in the real jquery object.
Let's go into the real implementation section, which is $, the statement of the JQuery object, where the two most basic members are listed:
Copy Code code as follows:

var jQuery = (function () {
var jQuery = function (selector, context) {
The Real initialization function
Return to New JQuery.fn.init (selector, context, rootjquery);
},
A large pile of variable declarations
FN is the primary function implementation point and the starting point for jquery plug-ins. It's actually a JS prototype.
Jquery.fn = Jquery.prototype = {
};
A function used by an extended object to dynamically add members to an object. Later, the addition of members to jquery is done with the Extend function.
Jquery.extend = JQuery.fn.extend = function () {
};
// ...
return jQuery;
})();

The jquery object is the core object, all $ (...) Are all jquery objects, and most of the functions are added to the jquery object with a extend method, except for a few direct implementations of the utility function under jquery.

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.