String对象的“instanceof”与“string”文字的“instanceof”

时间:2012-04-04 18:59:00

标签: javascript inheritance javascript-objects instanceof prototypal-inheritance

  

可能重复:
  Why does instanceof return false for some literals?

有谁知道为什么x不是String / Object的实例?

var x = "abc",
y = new String("XYZ");

x instanceof String; // False
x instanceof Object; // False
y instanceof String; // True
(x.constructor === y.constructor) //True

http://jsfiddle.net/pCfWC/6/

0 个答案:

没有答案
相关问题