Looking at the example given on this MDN page
const o = {a: 0};
Object.defineProperty(o, 'b', { get: function() { return this.a + 1; } });
console.log(o.b) // Runs the getter, which yields a + 1 (which is 1)
console.log(o)
Why, when I log o
, why do I:
Not see it in node.js
?
See it but it's greyed out in Chrome?
If you add enumerable: true
to the defineProperty()
options object, you'll see it. By default, properties added with .defineProperty()
are not enumerable.
Some console environments might choose to show all properties, others don't.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With