标签:
var str = ‘asdf‘;?
var str1 = new String(‘asdf‘);
typeof str;//"string"
typeof str1;//"object"
Object.prototype.toString.cal(str); //"[object String]"
Object.prototype.toString.call(str1); //"[object String]"
综上所述,判断是否为字符串使用下边的最保险
Object.prototype.toString.call(str) === "[object String]"
|
标签:
原文地址:http://my.oschina.net/u/1169535/blog/411096