[英]Where in the ECMAScript specification can I find the reason about why {} !== {}?
In JavaScript We all know that {} !== {}
- they are different objects allocated on heap.在 JavaScript 我们都知道
{} !== {}
- 它们是在堆上分配的不同对象。 But I was trying to find the reason at the language specification level.但我试图在语言规范级别找到原因。
at https://tc39.es/ecma262/#sec-samevaluenonnumeric it says在https://tc39.es/ecma262/#sec-samevaluenonnumeric它说
- If x and y are the same Object value, return true.
如果 x 和 y 是相同的 Object 值,则返回 true。 Otherwise, return false.
否则,返回假。
But it is unclear to me how the spec defines exactly when two objects are considered to have the same Object value.但我不清楚规范如何准确定义两个对象何时被认为具有相同的 Object 值。 Like
{}
and {}
clearly do not have the same value but how exactly is it defined in the spec?像
{}
和{}
显然没有相同的值,但它在规范中究竟是如何定义的?
{}
in this context is an ObjectLiteral , when the runtime evaluation encounters such an ObjectLiteral it calls OrdinaryObjectCreate which itself calls MakeBasicObject which does return a new object. {}
在这种情况下是一个ObjectLiteral ,当运行时评估遇到这样的 ObjectLiteral时,它会调用OrdinaryObjectCreate ,后者本身会调用MakeBasicObject ,后者确实返回一个新的 object。
So two ObjectLiterals can't be SameObject.所以两个 ObjectLiterals 不能是 SameObject。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.