判断类型

 

 

1 let objType = {}
2 'Array Date RegExp Object Error'.split(' ').forEach(e => objType['[object ' + e + ']'] = e.toLowerCase())
3 function type(obj) {
4     if(obj==='null'){
5         return String(obj)
6     }
7     return typeof obj === 'object' ? objType[Object.prototype.toString.call(obj)] : typeof obj
8 }

 

相关文章:

  • 2022-01-09
  • 2021-05-29
  • 2021-06-29
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-30
  • 2021-11-09
  • 2021-07-03
  • 2022-03-01
  • 2022-02-01
相关资源
相似解决方案