前言
JS 对于基础类型判断非常弱, 网上方法很乱且不好记, 又不愿意用库.
__ JS 类型__
- NaN
- null undefined
- Object String Number Boolean
- Array Function Symbol
__ 一行判断方法:__
- isNaN(NaN) //true , 特殊
- Object.prototype.toString.call(null) ; // [object Null]
- Object.prototype.toString.call(undefined) ; // [object Undefined]
- Object.prototype.toString.call({
- }) ; // [object Object]
- Object.prototype.toString.call('') ; // [object String]
- Object.prototype.toString.call(1) ; // [object Number]
- Object.prototype.toString.call(true) ; // [object Boolean]
- Object.prototype.toString.call([]) ; // [object Array]
- Object.prototype.toString.call(new Function()) ; // [object Function]
- Object.prototype.toString.call(Symbol()); // [object Symbol]
来源: http://www.jianshu.com/p/9f2268d44060