Path: csiph.com!aioe.org!news.mb-net.net!open-news-network.org!.POSTED.132.227.197.178.dynamic.wless.zhbmb00p-cgnat.res.cust.swisscom.ch!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Object equals other object Date: Tue, 17 Sep 2019 00:53:28 +0200 Organization: PointedEars Software (PES) Lines: 58 Message-ID: <1886272.oMNUckLgyt@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit Injection-Info: gwaiyur.mb-net.net; posting-host="132.227.197.178.dynamic.wless.zhbmb00p-cgnat.res.cust.swisscom.ch:178.197.227.132"; logging-data="31879"; mail-complaints-to="abuse@open-news-network.org" User-Agent: KNode/4.14.10 Cancel-Lock: sha1:5gVAx7nnpYzAATOSRZLhWLILXMU= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. If I have > > let a = { "c": 1 }, > b = { "c": 1 }; > > then > > console.log(a === b); // false. > > My question is, why was it decided that JavaScript is to return false > even if the two objects have the same number of properties, all the > properties are named the same, and all the properties values are > identical? History suggests that Brendan Eich decided to define it so for his language because Java works this way. See also my Bachelor thesis (), subsection 2.1 “ECMAScript”, and references. Presumably Java, among other programming languages, defined it so because it is easier and more efficient to compare two references to one object each than to compare all properties of those objects. Because then you only have to compare two pointer values. Note that in order for two objects to be equal in all properties, not only the properties of the object has to be compared, but also the properties of their superclasses (in ECMAScript: objects in their prototype chain), i.e. the memory areas where the data of the objects are stored and the memory areas where the data of their superclasses are stored. Java has the equals() method to facilitate the customizable comparison of objects based on their properties. Unlike ECMAScript, this requirement also extends to strings: "foo" == "foo" yields `false' in Java, while "foo".equals("foo") yields true. This is actually useful because it also handled Unicode composition. In ECMAScript we usually get away with `==' because we consider only ASCII characters; semantically, "e" + "\u0300" == "è" should yield `true' but does not, and to date there is apparently no method defined in ECMAScript to do a proper comparison; String.prototype.localeCompare(), ECMA-402, §14.1.1 just ignores the accent, it does not actually compare the composed/decomposed sequences. -- PointedEars FAQ: | | Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.