Skip to content

Instantly share code, notes, and snippets.

@brunoczim
Created May 30, 2017 13:49
Show Gist options
  • Save brunoczim/5edf9664e9e60b2decb904cb7c40692e to your computer and use it in GitHub Desktop.
Save brunoczim/5edf9664e9e60b2decb904cb7c40692e to your computer and use it in GitHub Desktop.
A simple snippet for reducing code when extending prototypes .
Function.prototype.extends = function(Parent) {
this.prototype = Object.create(Parent.prototype);
this.prototype.constructor = this;
};
//Now
/*
function Rectangle(w, h) {
this.width = w;
this.height = h;
}
Rectangle.prototype.getArea = function() {
return this.height * this.width;
}
function Square(size) {
Rectangle.call(this, size, size);
}
Square.extends(Rectangle);
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment