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); } }; }();
javascript类型校验
最新推荐文章于 2023-08-07 20:47:49 发布
本文介绍了一个JavaScript实用函数库,该库提供了一系列用于检查变量类型的函数,包括但不限于检查对象、数组、字符串、数字等类型。这些函数通过利用`Object.prototype.toString.call()`方法确保了类型检查的准确性和跨浏览器兼容性。
857

被折叠的 条评论
为什么被折叠?



