给定
var o = {};
var p = new Object();
p === o; //false
o.__proto__===p.__proto__ // true
为什么这是错误的?
请告诉我返回 false 的直接原因??
最佳答案
对象的===
is defined as :
11.9.6 The Strict Equality Comparison Algorithm
The comparison
x === y
, wherex
andy
are values, producestrue
orfalse
. Such a comparison is performed as follows:...
7. Return
true
ifx
andy
refer to the same object. Otherwise, returnfalse
.
在这种情况下,虽然两者都是空对象,但它们是单独创建的,因此不引用同一个对象。
作为旁注,两种结构做同样的事情;但通常的做法是使用 {}
。
关于javascript - 在 javascript 中,为什么是 {}!==Object()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8699816/