Created
February 2, 2012 09:22
-
-
Save cironunes/1722534 to your computer and use it in GitHub Desktop.
Simple inheritance example
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 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