简单判断传入值的类型
可以简单判断出来numbe string boolean function undefined object array null
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| function type(target){ var strTemple = typeof(target); var toStr = Object.prototype.toString; if(strTemple == 'object'){ switch(toStr.call(target)){ case '[object Array]': return 'array'; case '[object Object]': return 'object'; case '[object Number]': return 'object-number'; case '[object String]': return 'object-string'; case '[object Boolean]': return 'object-boolean'; case '[object Null]': return 'null'; } if(target===null){ return null } }else{ return strTemple; } }
|