1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 1× 1× 9× 9× 1× 82× 8× 74× 74× | const types = 'Boolean Number String Function Array Date RegExp Object Error'.split(' ') const class2type = {} for (let i = 0; i < types.length; i++) { class2type['[object ' + types[i] + ']'] = types[i].toLowerCase() } export default function type (obj) { if (obj === null) { return obj + '' } return typeof obj === 'object' || typeof obj === 'function' ? class2type[Object.prototype.toString.call(obj)] || 'object' : typeof obj } |