Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//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
You can’t perform that action at this time.