jQuery的一個關鍵函數

來源:互聯網
上載者:User

標籤:io   ar   for   sp   on   cti   代碼   bs   amp   

jQuery.extend = jQuery.fn.extend = function() {
 // copy reference to target object
 var target = arguments[0] || {}, a = 1, al = arguments.length, deep = false;

 // Handle a deep copy situation

//這個IF條件基本上總是false,只有當target對象是布爾類型時才會是真,也就是這段代碼好像沒有什麼作用

  if ( target.constructor == Boolean ) {   
  deep = target;
  target = arguments[1] || {};
 }

 // extend jQuery itself if only one argument is passed
 if ( al == 1 ) {
  target = this;
  a = 0;
 }

 var prop;

 for ( ; a < al; a++ )
  // Only deal with non-null/undefined values
  if ( (prop = arguments[a]) != null )
   // Extend the base object
   for ( var i in prop ) {
    // Prevent never-ending loop
    這一段代碼不知道怎麼搞的,說是用來阻止死迴圈,但我怎麼也不明白他是如何阻止的,好像卻了他也沒什麼影響。
    if ( target == prop[i] )
     continue;

    // Recurse if we‘re merging object values
    if ( deep && typeof prop[i] == ‘object‘ && target[i] )
     jQuery.extend( target[i], prop[i] );

    // Don‘t bring in undefined values
    else if ( prop[i] != undefined )
     target[i] = prop[i];
   }

 // Return the modified object
 return target;
};

 

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.