Skip to content

Instantly share code, notes, and snippets.

@andyjbas
Created January 30, 2013 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyjbas/4670921 to your computer and use it in GitHub Desktop.
Save andyjbas/4670921 to your computer and use it in GitHub Desktop.
function Car( model, year, miles ) {
this.model = model;
this.year = year;
this.miles = miles;
}
// Note here that we are using Object.prototype.newMethod rather than
// Object.prototype so as to avoid redefining the prototype object
Car.prototype.toString = function () {
return this.model + " has done " + this.miles + " miles";
};
// Usage:
var civic = new Car( "Honda Civic", 2009, 20000 );
var mondeo = new Car( "Ford Mondeo", 2010, 5000 );
console.log( civic.toString() );
console.log( mondeo.toString() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment