3. Construct a jquery object
3.1 Source structure
First look at the overall structure, then do the decomposition:
(function(window, undefined) {varJQuery = (function() { //Building a jquery object varJQuery =function(Selector, context) {return NewJQuery.fn.init (Selector, context, rootjquery); } //jquery Object PrototypesJquery.fn = Jquery.prototype ={constructor:jquery, init:function(selector, context, rootjquery) {//Selector has the following 7 branching conditions: //DOM Element //Body (optimized) //strings: HTML tags, html strings, #id, selector expressions //function (as ready callback function) //finally returns a pseudo-array } }; //Give the init function The JQuery prototype for later instantiationJQuery.fn.init.prototype =Jquery.fn; //merge content into the first parameter, most of the subsequent functions are extended through the function //with JQuery.fn.extend extended functions, most will call functions with the same name extended by Jquery.extendJquery.extend = JQuery.fn.extend =function() {}; //extending the static method on jqueryJquery.extend ({//Ready Bindready //Isplainobject Isemptyobject //Parsejson Parsexml //Globaleval //Each makearray inArray merge grep map //Proxy //Access //Uamatch //Sub //Browser }); //here, the jquery object is constructed, and the code behind it is an extension of the jquery or jquery object. returnJQuery; })(); Window.jquery= window.$ =jQuery;}) (window);
jquery Source Code Analysis-03 constructs jquery objects-source code structure and core functions