Skip to content

Instantly share code, notes, and snippets.

@zmts
Last active October 28, 2015 12:22
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 zmts/e6605e6ffacdef0905bd to your computer and use it in GitHub Desktop.
Save zmts/e6605e6ffacdef0905bd to your computer and use it in GitHub Desktop.
Decorator
// https://ru.wikipedia.org/wiki/Декоратор_(шаблон_проектирования)
// Класс для последующего декорирования
function Coffee() {
this.cost = function() {
return 1;
};
}
// Decorator A
function Milk(func) {
this.cost = function() {
return func.cost() + 0.5;
};
}
// Использование:
var cup = new Milk(new Coffee());
console.log(cup.cost());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment