Skip to content

Instantly share code, notes, and snippets.

@antoniocapelo
Created September 13, 2014 10:51
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 antoniocapelo/843210aa49d9b46acbcf to your computer and use it in GitHub Desktop.
Save antoniocapelo/843210aa49d9b46acbcf to your computer and use it in GitHub Desktop.
Extending Classes in Javascript (Prototypal pattern)
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