Created
September 6, 2017 07:32
-
-
Save tkssharma/187297e60899902dc8c805d05840d33a to your computer and use it in GitHub Desktop.
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 extend(Child, Parent) { | |
var F = function () {}; | |
F.prototype = Parent.prototype; | |
Child.prototype = new F(); | |
Child.prototype.constructor = Child; | |
Child.uber = Parent.prototype; | |
} | |
// Using this function (or your own custom version of it) helps you keep your code clean with regard to the repetitive inheritance-related tasks. This way you can inherit by simply using: | |
// Copy | |
extend(TwoDShape, Shape); | |
function extend(child,parent){ | |
var F = function(); | |
F.prototype = parent.prototype; | |
child.prototype = new F() | |
child.prototype.constructor = child; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment