/**************************************** 检测是否是数组对象 *****************************************/ var isArray = Function.isArray || function(o){ return typeof o === 'object' && Object.prototype.toString.call(o) === '[object Array]'; }
//判定o是否是一个类数组对象 //字符串和函数有length属性,但是它们可以用typeof检测将其排除。 //在客户端javascript中,DOM文本节点也有length属性,需要用额外判断o.nodeType != 3将其排除 function isArrayLike(o){ if(o && //o非null、undefined等 typeof o === 'object' && //o是对象 isFinite(o.length) && //o.length是有限数值 o.length >= 0 && //o.length是非负值 o.length === Math.floor(o.length) && //o.length是整数 o.length < 4294967296){ //o.length < 2^32 return true; //o是类数组对象 }else{ return false; //否则它不是 } }
//classof()函数,返回传递给它的任意对象的类 function classof(o){ if(o === null){ return "Null"; }; if(o === undefined){ return "Undefined"; }; return Object.prototype.toString.call(o).slice(8, -1); }
/**************************************** 检测是否是函数对象 *****************************************/ function isFunction(x){ return Object.prototype.toString.call(x) === "[object Function]"; }