Created
September 13, 2014 10:51
-
-
Save antoniocapelo/843210aa49d9b46acbcf to your computer and use it in GitHub Desktop.
Extending Classes in Javascript (Prototypal pattern)
This file contains hidden or 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 ClassName(name) { | |
this.name = name; | |
} | |
ClassName.prototype = { | |
constructor: ClassName, | |
greet: function () { | |
return 'My name is' + this.name; | |
} | |
}; | |
function SubClassName(name, stuff) { | |
ClassName.call(this, name); // call the super class constructor | |
this.stuff = stuff; | |
} | |
SubClassName.prototype = new ClassName(); // inherit the prototype | |
SubClassName.prototype.constructor = SubClassName; // set our constructor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment