jq源碼學習7_function isArraylike( ) {} 類似數組的判斷(內部使用)

//7.function isArraylike( ) {} 類似數組的判斷(內部使用)
 function isArraylike(obj){
   var length = obj.length,
   type = jQuery.type(obj);
   //jQuery.isWindow()函數用於判斷指定參數是否是一個窗口
   if(jQuery.isWindow(obj)){
        return false;
   }
   if(obj.nodeType ===1 && length){
      return true;
   }
   return type === "array" || type !== "function" && 
   ( length === 0 ||
		typeof length === "number" && length > 0 && ( length - 1 ) in obj );
 }
//7.function isArraylike( ) {} 類似數組的判斷(內部使用)
//通過jQuery選擇document元素賦給rootjQuery,rootjQuery就是document。
//這樣做有利於壓縮以及代碼的易讀性(通常我們習慣將一個值其賦給一個變量)。
rootjQuery = jQuery(document);

 

發佈了133 篇原創文章 · 獲贊 27 · 訪問量 24萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章