Skip to content

Instantly share code, notes, and snippets.

@winarcooo
Last active April 13, 2019 16:37
Show Gist options
  • Save winarcooo/399940ed50367bbe8fdf8fe4ecadf2c9 to your computer and use it in GitHub Desktop.
Save winarcooo/399940ed50367bbe8fdf8fe4ecadf2c9 to your computer and use it in GitHub Desktop.
/**
* prototype is just way of saying for this object use other object
* as a backup/delegate/prototype
* if someone call my object with a property that doesn't exist on my object
* go lookin this other object
*/
function talk() {
console.log(this.sound)
}
let animal = {
talk
}
let dog = {
sound: 'woof'
}
let scoobyDoo = {
howl: function() {
console.log(this.sound.toUpperCase())
}
}
Object.setPrototypeOf(dog, animal)
Object.setPrototypeOf(scoobyDoo, cat)
dog.talk() // woof
scoobyDoo.howl() // WOOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment