JS 的一个设计上的bug(疑似)

今天测试一段代码的时候发现:


var str1 = 'hello world'

console.log(str1 instanceof String)  //  输出false

console.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.

我想问的是, 为什么这两个结果不同呢?


呼如林
浏览 390回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript