Skip to content

Instantly share code, notes, and snippets.

@futurist
Forked from MartinSvarrer/es5_inheritance
Created January 29, 2016 04:16
Show Gist options
  • Save futurist/38fa704b38285fbc817b to your computer and use it in GitHub Desktop.
Save futurist/38fa704b38285fbc817b to your computer and use it in GitHub Desktop.
ES5 way of doing inheritance
function SuperClass () {};
SuperClass.prototype = {
constructor: SuperClass,
a: 'Hello',
b: 'super',
c: function () {
return this.a + ', ' + this.b + '!';
}
};
function Sub () {};
Sub.prototype = Object.create(SuperClass.prototype, {
constructor: { value: Sub },
b: { value:'sub' }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment