Skip to content

Instantly share code, notes, and snippets.

@sagaban
Created August 23, 2016 16:59
Show Gist options
  • Save sagaban/0638afc118e4e5253909c82cee80b798 to your computer and use it in GitHub Desktop.
Save sagaban/0638afc118e4e5253909c82cee80b798 to your computer and use it in GitHub Desktop.
function talk(){
console.log(this.sound);
}
let animal = {
talk
};
let cat = {
sound: "Miau!"
};
Object.setPrototypeOf(cat, animal);
cat.talk();
let dog = {
sound: 'Guau!'
}
let nDog = Object.assign(dog, animal);
nDog.talk();
/*let otherDog = Object.create(animal, dog);
otherDog.talk();*/
let catFromDogTalk = nDog.talk.bind(cat);
catFromDogTalk();
let bigDog = {
ladrar: function() {
console.log(this.sound.toUpperCase());
}
}
Object.setPrototypeOf(bigDog, dog);
bigDog.ladrar()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment