1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| <script type="text/javascript"> let _obj = { isNumeric: "Number", isFunction: "Function", isString: "String", isNull: "Null", isUndefined: "Undefined", isSymbol: "Symbol", isPlainObject: "Object", isArray: "Array", isRegExp: "RegExp", isDate: "Date", isWindow: "Window", isBoolean: "Boolean" }, _toString = ({}).toString, _type = {}; for (let key in _obj) { if (!_obj.hasOwnProperty(key)) break let reg = new RegExp("\\[object "+ _obj[key] +"\\]") _type[key] = function (value) { return reg.test(_toString.call(value)) } } console.log(_type.isNumeric(12)); console.log(_type.isNumeric("sss")); console.log(_type.isFunction(Array)); </script>
|