判断类型

 

 

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 }

 

posted @ 2020-05-07 16:36  yinping  阅读(157)  评论(0编辑  收藏  举报