Skip to content

Instantly share code, notes, and snippets.

@tkssharma
Created September 6, 2017 07:32
Show Gist options
  • Save tkssharma/187297e60899902dc8c805d05840d33a to your computer and use it in GitHub Desktop.
Save tkssharma/187297e60899902dc8c805d05840d33a to your computer and use it in GitHub Desktop.
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