Skip to content

Instantly share code, notes, and snippets.

@cironunes
Created February 2, 2012 09:22
Show Gist options
  • Save cironunes/1722534 to your computer and use it in GitHub Desktop.
Save cironunes/1722534 to your computer and use it in GitHub Desktop.
Simple inheritance example
function inherit( Parent, Child ) {
Child.prototype = new Parent();
}
function Car( name ) {
this.name = name;
}
Car.prototype.drive = function () {
return 'Driving a ' + this.name + ' like a boss';
}
function Motocycle( name ) {}
inherit( Car, Motocycle );
var hd = new Motocycle();
hd.name = 'Harley Davidson';
console.log(hd.drive()); //Driving a Harley Davidson like a boss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment