//就好像快餐店有单点和套餐,组合模式提供了一个清晰的层级结构
//比如要创建一些dom层级
//统一虚拟父类
var A = function(){}
A.prototype = {}
//容器类
var Container = function(){
//构造函数继承父类
A.call(this);
//....
}
//寄生式继承父类原型方法
inheritPrototype(Container, A);
Container.prototype = {};
//下一层有两个dom
var b = function(){
//构造函数继承父类
A.call(this);
//....
}
inheritPrototype(b, A);
b.prototype = {};
var c = function(){
//构造函数继承父类
A.call(this);
//....
}
inheritPrototype(c, A);
c.prototype = {};
//使用,添加dom节点
var A1 = new Container();
A1.add(
new b().add(
//如果还有下一级可以继续add下去
)
)
var A1 = new Container();
A1.add(
new c();
)
从二十五开始到三十一的设计模式属于结构型设计模式
林秀栋的技术博客