Skip to content

Instantly share code, notes, and snippets.

@ansarisufiyan777
Created September 2, 2019 11:54
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 ansarisufiyan777/37336dfe68199b93b650f50c375955d9 to your computer and use it in GitHub Desktop.
Save ansarisufiyan777/37336dfe68199b93b650f50c375955d9 to your computer and use it in GitHub Desktop.
//prototype design patterns
exports.RunPrototype = () => {
TeslaModels = function () {
this.numWheels = 4;
this.manufacturer = 'Tesla';
this.make = 'Model S';
}
TeslaModels.prototype = function () {
var go = function () {
// Rotate wheels
console.log("GO", this)
};
var stop = function () {
// Apply brake pads
console.log("stop", this)
};
return {
pressBrakePedal: stop,
pressGasPedal: go
}
}()
var tm = new TeslaModels();
console.log(tm.pressBrakePedal())
console.log(tm.pressGasPedal())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment