Skip to content

Instantly share code, notes, and snippets.

@mplatts
Created December 7, 2014 00:16
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 mplatts/6e2138ab8c41dbff83ca to your computer and use it in GitHub Desktop.
Save mplatts/6e2138ab8c41dbff83ca to your computer and use it in GitHub Desktop.
Standard inheritance in Javascript
function MyClass(){
}
MyClass.prototype.method = function(){}
function MySubClass(){
// use MyClass as the constructor
MyClass.call(this);
}
MySubClass.prototype = Object.create(MyClass.prototype);
MySubClass.prototype.constructor = MySubClass;
MySubClass.prototype.method = function(){
MyClass.prototype.method.call(this); // same as going super()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment