简体   繁体   中英

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. But I was trying to find the reason at the language specification level.

at https://tc39.es/ecma262/#sec-samevaluenonnumeric it says

  1. If x and y are the same Object value, return 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. 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.

So two ObjectLiterals can't be SameObject.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM