Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save schalkneethling/400afae5e60da0ee01d22f1d7556f1f3 to your computer and use it in GitHub Desktop.
Save schalkneethling/400afae5e60da0ee01d22f1d7556f1f3 to your computer and use it in GitHub Desktop.
// https://nationalkitty.com/cat-ancestry-where-do-cats-come-from/
const pantherinae = {
roar: function () {
console.log(`${this.name} is roaring!`);
},
domesticated: false,
size: "large",
sound: "roar",
};
const acinonychinae = Object.create(pantherinae, {
roar: { value: undefined },
size: { value: "medium" },
sound: { value: undefined },
});
const felisSilvestrisCatus = Object.create(acinonychinae, {
purr: {
value: function () {
return `${this.name} is purring!`;
},
},
sound: { value: "purr" },
});
const em = Object.create(felisSilvestrisCatus, {
domesticated: { value: true },
name: { value: "Em" },
size: { value: "small" },
});
const cheetah = Object.create(acinonychinae);
const lion = Object.create(pantherinae, {
name: { value: "Alex" },
});
console.log(
`${em.name} is ${em.size} and can ${
em.sound
}(${em.purr()}), but cannot roar(${em.roar}).`
);
console.log(`Is a cat domesticated? ${em.domesticated}`);
lion.roar();
console.log(`Is a lion domesticated? ${lion.domesticated}`);
console.log(`Is a cheetah domesticated? ${cheetah.domesticated}`);
console.log(`What sound does a cheetah make? ${cheetah.sound}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment