Created
December 9, 2016 23:22
-
-
Save dperrymorrow/6638bbe377d2e690a9873ecee68a60b4 to your computer and use it in GitHub Desktop.
Factory Pattern with "Inheritance"
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
const animal = () => { | |
return { | |
name: 'animal', | |
eat() { | |
console.log(`my name is ${this.name} i am a eating`); | |
} | |
}; | |
} | |
const dog = (name) => { | |
const type = 'dog'; | |
return Object.assign(animal(), { | |
name: name, | |
speak() { | |
console.log(`my name is ${this.name} i am a ${type}`); | |
} | |
}); | |
} | |
let spot = dog('spot'); | |
spot.speak(); | |
// my name is spot i am a dog | |
spot.eat(); | |
// my name is spot i am eating |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment