抽象一个类型判断库 发表于 2023-02-21 1234567891011121314151617181920212223export function type(x) { const t = typeof x if (x === null) { return 'null' } if (t !== 'object') { return t } const toString = Object.prototype.toString const innerType = toString.call(x).slice(8, -1) const innerLowType = innerType.toLowerCase() if (['String', 'Boolean', 'Number'].includes(innerType)) { return innerType } if (typeof x?.constructor?.name === 'string') { return x.constructor.name } return innerLowType}