Skip to content

Instantly share code, notes, and snippets.

@drenther
Created July 1, 2018 15:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save drenther/b479d1c4ea65a87faf60e7e8c853c9b6 to your computer and use it in GitHub Desktop.
Save drenther/b479d1c4ea65a87faf60e7e8c853c9b6 to your computer and use it in GitHub Desktop.
Creational Pattern - Prototype
// using Object.create as was recommended by ES5 standard
const car = {
noOfWheels: 4,
start() {
return 'started';
},
stop() {
return 'stopped';
},
};
// Object.create(proto[, propertiesObject])
const myCar = Object.create(car, { owner: { value: 'John' } });
console.log(myCar.__proto__ === car); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment