Skip to content

Define underscore properties as non-enumerable #58

Open
@DonovanDMC

Description

As it sits currently, models can be very hard to read when logged due to the numerous underscored properties (which I assume to be private, "don't use this" properties). These properties are shown when logging to the console, and you have to go out of your way to hide them, or sift through them for the actual data on the model. This can be combatted with simple defineProperty/defineProperties call

const obj = {};
Object.defineProperty(obj, "hidden1", { value: "whatever", enumerable: false });
Object.defineProperty(obj, "_hidden2", { value: "hi", enumerable: false });
Object.defineProperties(obj, {
    hidden3: {
        value: "this is easy",
        enumerable: false
    },
    _hidden4: {
        value: "please my adhd is killing me",
        enumerable: false
    }
});

console.log(obj);
console.log(obj.hidden1);
console.log(obj._hidden2);
console.log(obj.hidden3);
console.log(obj._hidden4);

The first log shows no properties, but the next 4 clearly show them as still accessible and usable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions