手写 typeof

发布时间 2023-05-29 22:42:41作者: 睡成蛆

function myTypeof(o,type){ const types = { 'string': true, 'number': true, 'symbol': true, 'bigint': true, 'function': true, 'boolean': true, 'undefined': true, 'null': false, 'array': false, 'object': false, } let k = Object.prototype.toString.call(o).toLowerCase().slice(8,-1) return types[k]?k:'object' }