Last active
August 29, 2015 14:02
-
-
Save mauriciosoares/c35cd8c338c24e0330c8 to your computer and use it in GitHub Desktop.
This file contains 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 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