JS判断数据类型最稳定的方法
function whatType(input) {
let typeStr = Object.prototype.toString.call(input).match(/\[object\s(.*?)\]/)
return typeStr && typeStr[1]
}
console.log(whatType(123)) // Number
console.log(whatType('abc')) // String
console.log(whatType(false)) // Boolean
console.log(whatType([1,2,3])) // Array
console.log(whatType({name:'lili'})) // Object
console.log(whatType(undefined)) // Undefined
console.log(whatType(null)) // Null
console.log(whatType(function(){})) // Function