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);
发布了139 篇原创文章 · 获赞 27 · 访问量 24万+

猜你喜欢

转载自blog.csdn.net/chunchun1230/article/details/104181942
今日推荐