javascript类型校验

来源:互联网 发布:淘宝卖家加分规则 编辑:程序博客网 时间:2024/06/06 00:07
var TypeCheck = function(){    var __isType = function(type){        return function(obj){            return Object.prototype.toString.call(obj) === '[object '+ type +']';        };    };    return {        isObject : function(obj){            return __isType("Object")(obj);        },        isArray : function(obj){            return Array.isArray(obj) || __isType("Array")(obj);        },        isString : function(obj){            return __isType("String")(obj);        },        isUndefined : function(obj){            return __isType("Undefined")(obj);        },        isNumber : function(obj){            return  __isType("Number")(obj) && isFinite(obj) && !isNaN(obj);        },        isNullOrUndefined : function(obj){            return !!(obj == undefined);        }    };}();
0 0