Skip to content

Instantly share code, notes, and snippets.

@dperrymorrow
Last active December 9, 2016 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dperrymorrow/c35c973fd8a82d4fd5f99f610533367e to your computer and use it in GitHub Desktop.
Save dperrymorrow/c35c973fd8a82d4fd5f99f610533367e to your computer and use it in GitHub Desktop.
Simple Factory Pattern
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