Created
June 3, 2013 20:16
-
-
Save jdaly13/5701015 to your computer and use it in GitHub Desktop.
Inheritance Pattern Classical
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(C, P) { | |
var F = function () {}; | |
F.prototype = P.prototype; | |
C.prototype = new F(); | |
C.uber = P.prototype; | |
C.prototype.constructor = C; | |
} | |
function Parent () {} | |
Parent.prototype.getName = function () { | |
return this.name | |
} | |
function Child(name, dob, maleOrFemale) { | |
this.name = name; | |
this.birthdate = dob; | |
this.sex = maleOrFemale; | |
} | |
inherit(Child, Parent); | |
var child = new Child("joe", "5/29/89", "male"); | |
child.getName() //outputs Joe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment