装饰者模式

用途

动态的给某个对象添加一些额外的职责,而不会影响从这个类中派生的其他对象。

简单的例子

var Plane=function() {
  
}
Plane.prototype.fire=function() {
  console.log('fire!');
}

var MissileDecorator=function(plane) {
  this.plane=plane;
}
MissileDecorator.prototype.fire=function() {
  console.log('missile!!');
  this.plane.fire();
}

var plane=new Plane();
plane=new MissileDecorator(plane);
plane.fire();

你可能感兴趣的:(装饰者模式)