Created
August 23, 2016 16:59
-
-
Save sagaban/0638afc118e4e5253909c82cee80b798 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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