Last active
December 15, 2015 01:48
-
-
Save tarao/5182203 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://blog.livedoor.jp/dankogai/archives/51859373.html | |
var x = { a: 1, b: 2, c: 3 }; | |
var y = { a: 1, b: 2, c: 3, d: 4 }; | |
var z = {a: 1, b: 2, c: 3 }; | |
var w = {a: 1, b: 2, c: 3, d: 4 }; | |
x.b = w; | |
y.b = x; | |
z.b = y; | |
w.b = x; | |
Object.equals(x, z); // false | |
Object.equals(z, x); // true | |
Object.equals(y, w); // true | |
Object.equals(w, y); // false | |
/* How to check deep equality precisely? | |
cf. "Deep equality revisited" | |
S. Abiteboul and J. Van den Bussche | |
Deductive and Object-Oriented Databases, Lecture Notes in Computer Science, vol 1013, pages 213-228. Springer, 1995. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I thought that
Object.equals
is a structural equivalence forvalues and a reference is not a value. In this case, it should
examine the structures of
x
andz
as values of infinite treesand should not be sensitive to self-reference since the "values"
do not contain references by definition. (I'm talking about the
formal definition of values for a particular structural
equivalence relation, not the implementation of values in
JavaScript.)
I'm not disagreeing with your opinion that the current
implementation of
Object.equals
somehow makes sense, as long asits formal definition is well-defined. I understand that the
formal definition is different from what I thought.
Unfortunately, I found that the current implementation of
Object.equals
is not well-defined, at least as an equivalencerelation. The (updated) example shows that
Object.equals
is notsymmetric. I think the name
equals
implies that it is anequivalence relation (not necessarily a structural equivalence), i.e.,
a relation which is reflexive, symmetric and transitive. So I have to
conclude that
Object.equals
is not well-defined.