If it is to do the web, I believe it is not necessary to make additions and deletions to the Dom, it is believed that we have more or less contact with the JQuery class library, its biggest feature is a powerful selector, so that developers out of the original JS a lot of getElementById, Getelementsbyname ... The official provides an ultra-long method API.
JQuery overall source code, I also in the reading, temporarily recorded. (Why to look at the source code, the reason is very simple----a good understanding of the principle of jQuery two in order to install force).
when using jquery, you first need to introduce a jquery file, and then you can use the $, jquery call directly. Why is it?
Presumably, the students who have written JavaScript know that window is the top object, and like document, location, navigator and so on as window properties, for ease of use, you can omit window., then, JQuery Same principle.
In the source code of $, JQuery is also using this method to introduce window.$=window.jquery=xxx. , the page in the diagram introduces the JQuery library.
// Expose jquery to the global objectwindow.jquery = window.$ = jquery;
two JQuery library used in the process, the general use of two forms, one is $.ajax, $.noconflict, and the other is $ (method parameters) to use
The source shows that JQuery itself is a function, while $.ajax, $.noconflict can be thought of as a static method added by the function object, and the use of $ () is equivalent to calling the $ function method.
jquery = function (selector, context) {//The jquery object is actually just the Init constructor ' enhanced ' return new JQ Uery.fn.init (selector, context, rootjquery);},
Three jQuery source code in the function of self-executing functions, and self-executing functions of the window, undefined function?
(function(window, undefined) {...}) (window);
self-executing function: The function is automatically executed, and the user cannot be called manually outside, and is executed once. The self-executing function is equivalent to creating a special scope, which is closed to avoid polluting global variables. Here are just two common ways to do this.
(function () {
function body
})();
+ function A () {
function body
}();
In the JQuery source, the method passes through the window and undefined two parameters.
window: Because when the function is called, it needs to find the variable value, and if the current function scope does not have the variable, it will go up to the previous level to find, directly into the window, can reduce the search time, improve efficiency.
Undefined: After the landlord Test in IE 8, the undefined property value can be modified, at this time the incoming parameter undefined should be maintained undefined initial value.
Not to be continued.
jquery Source Code Analysis one: jquery class library overall architecture design analysis