Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ascreven/276be29e3936a0341e8b to your computer and use it in GitHub Desktop.
Save ascreven/276be29e3936a0341e8b to your computer and use it in GitHub Desktop.
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