Forked from goldhand/javascript-prototype-solution.js
Last active
August 29, 2015 14:27
-
-
Save ascreven/276be29e3936a0341e8b to your computer and use it in GitHub Desktop.
Solution to this: https://gist.github.com/goldhand/ee3a60bdab87ccf7a52e
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() { // constructor | |
this.driverCount = 0; // this refers to the newly created object | |
} | |
Car.prototype.incrementDriverCount = function() { | |
// increments the driverCount of the instance of the new object invoking this method | |
this.driverCount++; // this still refers to the object who is invoking this function | |
return this.driverCount; | |
}; | |
var myCar = new Car(); | |
var myOtherCar = new Car(); | |
var myWeekendCar = new Car(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment