Comparing Properties with getters only
I have an immutable data structure defined as follow:
let DataStructure = function (name, description, imageUrl, linkUrl) {
let _name = name;
let _description = description;
let _imageUrl = imageUrl;
let _linkUrl = linkUrl;
Object.defineProperty(this, 'name', {
get: () => _name,
});
Object.defineProperty(this, 'description', {
get: () => _description,
});
Object.defineProperty(this, 'imageUrl', {
get: () => _imageUrl,
});
Object.defineProperty(this, 'linkUrl', {
get: () => _linkUrl,
});
};
Comparing to object instances with different values always returns true when it should return false.
Hey @ihachani thanks for the issue.
This is because those properties are non-enumerable, and deep-eql ignores non-enumerable properties. This is something we could perhaps change, but for now you can simple add enumerable: true to your defineProperty calls. Alternatively you could write a helper to handle these objects.
I added enumerable: true and it is working now. May I ask why deep-eql ignores enumerables? What would I gain/lose when I set it to true. Thanks.
It was a design decision, somewhat arbitrary. It may change in the future. What you gain/lose can probably best be explained by MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable