Skip to content

Instantly share code, notes, and snippets.

@bripkens
Created October 15, 2012 12:15
Show Gist options
  • Save bripkens/3892163 to your computer and use it in GitHub Desktop.
Save bripkens/3892163 to your computer and use it in GitHub Desktop.
Common Mixin approach
function extend(to, from) {
for (var key in from) {
if (from.hasOwnProperty(key)) {
to[key] = from[key];
}
}
}
function Label() { this.text = ''; };
Label.prototype.setLabel = function(text) { this.text = text || '' };
Label.prototype.getLabel = function() { return this.text;};
Label.prototype.renderLabel = function() {};
function Rectangle() {};
Rectangle.prototype.renderRectangle = function() {};
function LabeledRectangle() {};
extend(LabeledRectable.prototype, Label.prototype);
extend(LabeledRectable.prototype, Rectangle.prototype);
LabeledRectangle.prototype.render = function() {
this.renderRectangle();
this.renderLabel();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment