今天測試一段代碼的時候發現: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.我想問的是, 為什么這兩個結果不同呢?
JS 的一個設計上的bug(疑似)
呼如林
2018-10-11 14:09:37