日期:2014-05-16  浏览次数:20401 次

常用js判断方法[收藏]

转贴
isNull: function(a){  
    return a === null;  
},  
isUndefined: function(a){  
    return a === undefined;  
},  
isNumber: function(a){  
    return typeof a === 'number';  
},  
isString: function(a){  
    return typeof a === 'string';  
},  
isBoolean: function(a){  
    return typeof a === 'boolean';  
},  
isPrimitive: function(b){  
    var a = typeof b;  
    return !!(b === undefined || b === null || a == 'boolean' || a == 'number' || a == 'string');         
},  
isArray: function(a){  
    return proto_obj.toString.call(a) === '[object Array]';  
},  
isFunction: function(a){  
    return proto_obj.toString.call(a) === '[object Function]';  
},  
isPlainObject: function(o){  
    if (!o || o === win || o === doc || o === doc.body) {  
        return false;  
    }  
    return 'isPrototypeOf' in o && proto_obj.toString.call(o) === '[object Object]';          
},  
isWindow: function(o){  
    return o && typeof o === 'object' && 'setInterval' in o;  
},  
isEmptyObject: function(o){  
    for(var a in o) {  
    return false;  
    }  
    return true;  
}  
?