Skip to content

Instantly share code, notes, and snippets.

@FiNGAHOLiC
Created January 19, 2012 10:42
Show Gist options
  • Select an option

  • Save FiNGAHOLiC/1639352 to your computer and use it in GitHub Desktop.

Select an option

Save FiNGAHOLiC/1639352 to your computer and use it in GitHub Desktop.
Decorator Pattern
// http://shichuan.github.com/javascript-patterns/
var tree = {};
tree.decorate = function(){
console.log('Make sure the tree won\'t fall');
};
tree.getDecorator = function(deco){
tree[deco].prototype = this;
return new tree[deco];
};
tree.RedBalls = function(){
this.decorate = function(){
this.RedBalls.prototype.decorate();
console.log('Put on some red balls');
};
};
tree.BlueBalls = function(){
this.decorate = function(){
this.BlueBalls.prototype.decorate();
console.log('Add blue balls');
};
};
tree.Angel = function(){
this.decorate = function(){
this.Angel.prototype.decorate();
console.log('An angel on the top');
};
};
tree = tree.getDecorator('BlueBalls');
tree = tree.getDecorator('Angel');
tree = tree.getDecorator('RedBalls');
tree.decorate();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment