Skip to content

Instantly share code, notes, and snippets.

@mauriciosoares
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauriciosoares/c35cd8c338c24e0330c8 to your computer and use it in GitHub Desktop.
Save mauriciosoares/c35cd8c338c24e0330c8 to your computer and use it in GitHub Desktop.
function Sale(price) {
this.price = price || 100;
}
Sale.prototype.getPrice = function() {
return this.price;
};
Sale.prototype.decorate = function(decorator) {
var overrides = this.constructor.decorators[decorator],
newobj,
i;
newobj = Object.create(this);
newobj.uber = this;
for(i in overrides) {
newobj[i] = overrides[i];
}
return newobj;
};
Sale.decorators = {};
Sale.decorators.fedtax = {
getPrice: function() {
var price = this.uber.getPrice();
price += 1;
return price;
}
}
var sale = new Sale();
sale = sale.decorate('fedtax');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment