我正在努力加强我的JavaScript基础知识。所以问题是关于字符串字面量。它们不是对象
吗?如果你的答案是“是”,那么我的问题是为什么instanceof
返回false
?
> var s = new String
> s.constructor.toString()
function String() { [native code] }
> typeof s
object
> s instanceof String
true
> s instanceof Object
true
> s instanceof Number
false
迄今为止还不错。
> typeof 'c'
string
> 'c' instanceof Object
false
> 'c' instanceof String
false
> 'c'.length
1
> 'c'.charAt(0)
c
> 'c'.constructor.toString()
function String() { [native code] }