前端业务代码规范

<script>
    (function (global,$,_,doc) {
        var report=function (options) {

            this.eventsMap={
               'click #btn1':'btn1click',
               'click #btn2':'btn2click',
            };

            this.initializeElements();
            this.initialization();
        };
        
        report.Eles={
            a:"#a",
            b:"#b",
            c:"#c"
        };

        report.prototype={
            constructor:report,
            initializeElements:function () {
                var eles=report.Eles;
                for(var name in eles)
                {
                    if(eles.hasOwnProperty(name))
                    {
                        this[name]=$(eles[name]);
                    }
                }
               //  console.log(this.a.html());
               // console.log(this['a'].html());
            },

            initialization:function ()
            {
                this.bindEvent(this.eventsMap);
            },

            _scanEventsMap:function (maps,isOn) {
                var delegateEventSplit=/^(\S+)\s*(.*)$/;
                var bind=isOn ? this._delegate:this._undelegate;
                for(var keys in maps)
                {
                    if(maps.hasOwnProperty(keys))
                    {
                        var matches=keys.match(delegateEventSplit);
                        bind(matches[1],matches[2],this[maps[keys]].bind(this));
                    }
                }
            },
            initializeOrdinaryEvents:function (maps) {
                this._scanEventsMap(maps, true);
            },
            uninitializeOrdinaryEvents: function(maps) {
                this._scanEventsMap(maps);
            },
            _delegate:function (name,selector,func) {
                doc.on(name,selector,func);
            },
            _undelegate:function (name,selector,func) {
                doc.off(name,selector,func);
            },
            bindEvent:function (maps) {
                this.initializeOrdinaryEvents(maps);
            },
            unbindEvent: function(maps) {
                this.uninitializeOrdinaryEvents(maps);
            },
            destroy: function() {
                this.unbindEvent();
            },
            btn1click:function () {
                console.log("11111111111111");
            },
            btn2click:function () {
                console.log("222222222222");
            }
        };
        //暴露接口
        global.report=report;

        $(function () {
            new report();
        })
    }(this,this.jQuery,this._,this.jQuery(document)));
</script>

 

转载于:https://www.cnblogs.com/norm/p/6686470.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值