Created
July 1, 2018 15:22
-
-
Save drenther/b479d1c4ea65a87faf60e7e8c853c9b6 to your computer and use it in GitHub Desktop.
Creational Pattern - Prototype
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
// 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