With reference to Sam Elsamman's post, I'm enquiring if you have written a function which gives the expected behaviour to Object.create() please?
var animal = {traits: {}}; // a nested object as parent
var lion = Object.create(animal);
var bird = Object.create(animal);
lion.traits.legs = 4;
bird.traits.legs = 2;
console.log(lion.traits.legs); // 2
// edited following adiga's comment:`
animal.traits.hasOwnProperty("legs"); // true
I expect:
// edited following adiga's comment:
console.log(lion.traits.legs); // 4
animal.traits.hasOwnProperty("legs"); // false
Cheers
lionandbirdshare the same[[Prototype]]. So, adding a property totraitsupdates the same animal object.lion.hasOwnProperty("legs")to return true? Even if you didlion.traits = { legs: 4 }, it will still return false forlion.hasOwnProperty("legs")