Skip to content

Instantly share code, notes, and snippets.

@stujo
Created November 4, 2014 18:40
Show Gist options
  • Save stujo/85a81882ec8d2df7e009 to your computer and use it in GitHub Desktop.
Save stujo/85a81882ec8d2df7e009 to your computer and use it in GitHub Desktop.
Car With Prototype
function Car() {
this._speed = 0;
}
Car.prototype = {
currentSpeed: function() {
return this._speed;
},
stop: function() {
this._speed = 0;
return this.currentSpeed();
},
accelerate: function(delta) {
this._speed += delta;
return this.currentSpeed();
},
slow: function(delta) {
this._speed -= delta;
if (this._speed < 0) {
this._speed = 0;
}
return this.currentSpeed();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment