Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparing Properties with getters only #52

Open
ihachani opened this issue Feb 28, 2018 · 3 comments
Open

Comparing Properties with getters only #52

ihachani opened this issue Feb 28, 2018 · 3 comments

Comments

@ihachani
Copy link

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.

@keithamus
Copy link
Member

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.

@ihachani
Copy link
Author

ihachani commented Mar 5, 2018

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.

@keithamus
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants