读书人

extjs源码分析-002(js门类判断)

发布时间: 2012-11-22 00:16:41 作者: rapoo

extjs源码分析-002(js类型判断)

Ext = {};//Ext.apply = function(o,c,d){}//见extjs源码分析-001(Ext.apply)var toString = Object.prototype.toStringExt.apply(Ext, {         //isFinite --->返回true 表示值是非 NaN 、非负无穷和非正无穷       isNumber : function(v){//是否为数字            return typeof v === 'number' && isFinite(v);        },       isBoolean : function(v){//是否为布尔值            return typeof v === 'boolean';        },       isString : function(v){//是否为字符串            return typeof v === 'string';       },       isNumber : function(v){//是否在有限的数组范围内,不包括无穷大/小            return typeof v === 'number' && isFinite(v);        },       isFunction : function(v){//是否为Function类型            return toString.apply(v) === '[object Function]';        },       isPrimitive : function(v){//判断V的值是否为基本数据类型(数字/字符串/布尔值)            return Ext.isString(v) || Ext.isNumber(v) || Ext.isBoolean(v);        },       isObject : function(v){//判断是否为对象类型            return !!v && Object.prototype.toString.call(v) === '[object Object]';        },        isDate : function(v){//判断v是否为日期对象            return toString.apply(v) === '[object Date]';        },        isArray : function(v){//判断v的类型是否为数组            return toString.apply(v) === '[object Array]';        },       isEmpty : function(v, allowBlank){//判断V是否为空,如果v的值为null,或者v的值未定义,或者v是空数组,或者v的值允许为空则返回空字符串            return v === null || v === undefined || ((Ext.isArray(v) && !v.length)) || (!allowBlank ? v === '' : false);        },       isDefined : function(v){//v-->判断V是否定义            return typeof v !== 'undefined';        },        isElement : function(v) {//返回是否为html元素节点对象            return v ? !!v.tagName : false;        },        isIterable : function(v){//是否可以迭代            //check for array or arguments //数组 或者 多个参数            if(Ext.isArray(v) || v.callee){                return true;            }            //check for node list type //节点数组            if(/NodeList|HTMLCollection/.test(toString.call(v))){                return true;            }            //NodeList has an item and length property 节点下有节点项            //IXMLDOMNodeList has nextNode method, needs to be checked first.            return ((typeof v.nextNode != 'undefined' || v.item) && Ext.isNumber(v.length));        },})

读书人网 >JavaScript

热点推荐