shallow-equals currently considers undefined properties to be equal to properties which are not present, with the additional restriction that the number of own properties must be equal. This is somewhat counter-intuitive for comparisons such as the following:
Where copying the properties between two objects which compare equal causes them to become unequal.
An easy fix would be requiring b.hasOwnProperty after a.hasOwnProperty (which would also make the comparison symmetric when the inherited value of one object is the same as the own value of the other).
Another fix, which would allow less strict comparisons, would be to add additional ownProperty arguments to the comparison function so the caller can decide if it is considered equal. This is more difficult to implement, since the traversal of b would require value checking, but it would be more flexible.
shallow-equals
currently considersundefined
properties to be equal to properties which are not present, with the additional restriction that the number of own properties must be equal. This is somewhat counter-intuitive for comparisons such as the following:Where copying the properties between two objects which compare equal causes them to become unequal.
An easy fix would be requiring
b.hasOwnProperty
aftera.hasOwnProperty
(which would also make the comparison symmetric when the inherited value of one object is the same as the own value of the other).Another fix, which would allow less strict comparisons, would be to add additional ownProperty arguments to the comparison function so the caller can decide if it is considered equal. This is more difficult to implement, since the traversal of
b
would require value checking, but it would be more flexible.Either works for me.