var Type = (function() { var Type = {}; for (var i = 0, type; type = [‘Undefined‘, ‘Null‘, ‘Boolean‘, ‘Number‘, ‘String‘, ‘Function‘, ‘Array‘, ‘Object‘][i++]; ) { (function(type) { Type[‘is‘ + type] = function(obj) { return Object.prototype.toString.call(obj) === ‘[object ‘ + type + ‘]‘; }; })(type); }; return Type; })(); console.log(Type.isUndefined()); // true console.log(Type.isNull(a = null)); // true console.log(Type.isBoolean(false)); // true console.log(Type.isNumber(123)); // true console.log(Type.isString(‘str‘)); // true console.log(Type.isFunction(function() {})); // true console.log(Type.isArray([1, 2, 3])); // true console.log(Type.isObject({})); // true
时间: 2024-11-10 07:37:27