I don't understand why the property "salary" is not shown, despite being enumerable :
class People {
constructor(name, age) {
this.name = name;
this.age = age;
}
}
Object.defineProperty(People.prototype, 'salary', {
value: 3000,
enumerable: true,
writable: true
});
Execution :
> var p = new People('Jack', 46);
> console.log(p)
People { name: 'Jack', age: 46 }
> console.log(p.propertyIsEnumerable('salary'));
false
> console.log(p.salary)
3000
Why does it say false for p.propertyIsEnumerable('salary')
?
However, if I modify the property, suddenly it starts to be enumerated :
> p.salary = 4500
4500
> console.log(p)
People { name: 'Jack', age: 46, salary: 4500 }
> console.log(p.propertyIsEnumerable('salary'));
true
What's going on ? Why does it become enumerable only after modification ? Why isn't it enumerable from the beginning ?