- Object.prototype的toString()可以返回变量类型
- 而一般都重写了这个方法
- 借助call()
???????function classOf(x){ ???????????if(x === null) return "NULL"; ???????????if(x === undefined) return undefined; ???????????return Object.prototype.toString.call(x).slice(8,-1); ???????} ???????var x = 13; ???????console.log(classOf(x));
JS小tips 之 toString返回变量类型
原文地址:http://www.cnblogs.com/ideal-idiot/p/7813126.html