Created
November 4, 2014 18:40
-
-
Save stujo/85a81882ec8d2df7e009 to your computer and use it in GitHub Desktop.
Car With 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
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