-
-
Save futurist/38fa704b38285fbc817b to your computer and use it in GitHub Desktop.
ES5 way of doing inheritance
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 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