Last active
December 9, 2016 23:20
-
-
Save dperrymorrow/c35c973fd8a82d4fd5f99f610533367e to your computer and use it in GitHub Desktop.
Simple Factory Pattern
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 dog = (name) => { | |
const type = 'dog'; | |
return { | |
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 | |
let rufus = dog('rufus'); | |
rufus.speak(); | |
// my name is rufus i am a dog |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment