JS设计模式——责任链模式

模式作用:
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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值