今天测试一段代码的时候发现:var str1 = 'hello world'console.log(str1 instanceof String) // 输出falseconsole.log(str1.__proto__ === String.prototype) // 输出true对于这个结果感到很奇怪, 我以为是我对instanceof理解错了。 后来上MDN查了一下。 看了一下发现自己没有记错。 原文是这样的:The instanceof operator tests whether an object has in its prototype chain the prototype property of a constructor.我想问的是, 为什么这两个结果不同呢?
添加回答
举报
0/150
提交
取消