let animal = {
eats: true
};
let rabbit = Object.create(animal, {
jumps: {
value: true,
writable: true,
configurable: true
}
});
console.log(rabbit.__proto__); // logs: {eats: true};
console.log(animal); // logs: {eats: true};
console.log(rabbit.jumps); // logs: true;
console.log(rabbit); // logs {}
The question is: if rabbit is empty for real, what happend?
animal - has no jumps property
animal.proto - has no jumps property
rabbit - has no jumps property
rabbit.jumps - is true
Your new property is not enumerable - if it were it would show up in a text-based console (Your original code shows up in an object-based console like chrome for example):
const animal = {eats:true}
let rabbit = Object.create(animal, {
jumps: {
value: true,
writable: true,
configurable: true ,
enumerable:true
}
});
console.log(rabbit.__proto__); // logs: {eats: true};
console.log(animal); // logs: {eats: true};
console.log(rabbit.jumps); // logs: true;
console.log(rabbit); // logs as you expected
From the docs for Object.defineProperties():
enumerable
true if and only if this property shows up during enumeration of the properties on the corresponding object. Defaults to false.