js中 instanceof 检测 字符串

var str = 'str'
console.log(str instanceof String)   // false
console.log(typeof str)              // string

看上面的例子,str只是一个以string为数据类型的值,但并不属于String对象的实例

var strobj = new String('bbb')
console.log(strobj instanceof String)    // true

此时strobj就是String对象的一个实例了

猜你喜欢

转载自blog.csdn.net/magic_xiang/article/details/82623964