jQuery源碼分析-03構造jQuery對象-源碼結構和核心函數

來源:互聯網
上載者:User

標籤:log   isp   root   函數   代碼   標籤   分析   body   sem   

3. 構造jQuery對象

3.1源碼結構

先看看總體結構,再做分解:

(function( window, undefined ) {       var jQuery = (function() {       // 構建jQuery對象       var jQuery = function( selector, context ) {           return new jQuery.fn.init( selector, context, rootjQuery );       }          // jQuery對象原型       jQuery.fn = jQuery.prototype = {           constructor: jQuery,           init: function( selector, context, rootjQuery ) {              // selector有以下7種分支情況:              // DOM元素              // body(最佳化)              // 字串:HTML標籤、HTML字串、#id、選取器運算式              // 函數(作為ready回呼函數)              // 最後返回偽數組           }       };          // Give the init function the jQuery prototype for later instantiation       jQuery.fn.init.prototype = jQuery.fn;          // 合并內容到第一個參數中,後續大部分功能都通過該函數擴充       // 通過jQuery.fn.extend擴充的函數,大部分都會調用通過jQuery.extend擴充的同名函數       jQuery.extend = jQuery.fn.extend = function() {};             // 在jQuery上擴充靜態方法       jQuery.extend({           // ready bindReady           // isPlainObject isEmptyObject           // parseJSON parseXML           // globalEval           // each makeArray inArray merge grep map           // proxy           // access           // uaMatch           // sub           // browser       });         // 到這裡,jQuery物件建構完成,後邊的代碼都是對jQuery或jQuery對象的擴充       return jQuery;       })();       window.jQuery = window.$ = jQuery;})(window);

 

jQuery源碼分析-03構造jQuery對象-源碼結構和核心函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.