模式作用:
1,dom的冒泡有些类似职责链
2,nodejs当controller中有很多负责操作逻辑的时候拆分中间件
3,解耦发送者和接受者
注意事项:
1,JavaScript中的每一次【.】是有代价的,要在必要的时候应用
1,dom的冒泡有些类似职责链
2,nodejs当controller中有很多负责操作逻辑的时候拆分中间件
3,解耦发送者和接受者
注意事项:
1,JavaScript中的每一次【.】是有代价的,要在必要的时候应用
<meta charset="utf-8">
<script type="text/javascript">
function laoban(xiangmujingli){
if(xiangmujingli){
this.xiangmujingli=xiangmujingli;
}
}
laoban.prototype.write=function(php){
this.xiangmujingli.write(php);
}
function xiangmujingli(coder){
if(coder){
this.coder=coder;
}
}
xiangmujingli.prototype.write=function(php){
this.coder.write(php);
}
function coder(php){
//this.write(php);
}
coder.prototype.write=function(php){
console.log('coding....'+php);
}
//begin 发起 coder结束
var begin=new laoban(new xiangmujingli(new coder()));
begin.write('php');
</script>