• 模块的封装


    一:实例化多个(swipphoto之类的,一个页面多个实例)

    function index(name){
            this.name = name;
            this.init();//实例化后这个Init自动执行
        }
        index.prototype = {
            init: function(){
                //各种初始化方法
                this.initModel();
            },
            initModel: function(){
                console.log("初始化model");
            },
            getName: function(yourName){
                //对外暴露的方法
              return yourName + this.name;
            }
        }
        var a = new index("sss");
        var b = new index("bbb");
        var newName = a.getName("jjj");
        //indexCtrl后面的写在一个js中,作为一个模块
        var indexCtrl = (function(){
            function index(name){
                this.name = name;
                this.init();
            }
            index.prototype = {
                init: function(){
                    //各种初始化方法
                    this.initModel();
                },
                initModel: function(){
                    console.log("初始化model");
                },
                getName: function(yourName){
                    //对外暴露的方法
                    return yourName + this.name;
                }
            }
            return index;
        })()
        var a = new indexCtrl("sss");
        var newName = a.getName("jjj");

    二:组件式的,baseCtrl后面的单独写在一个Js里,作为模块

    var baseCtrl = (function(){
            var base = {
                //各种方法
                fn1:function(para){
                    return (para + 10);
                },
                fn2:function(){
    
                }
            };
            return base;
        })()
        var a = 1;
        a = baseCtrl.fn1(a);
  • 相关阅读:
    python中几种数据类型常用的方法
    WSGI
    从开学到初赛的一些个人总结
    CSP-S2020 浙江 游记
    CF1416D Graph and Queries
    单次期望 O(1) 的RMQ
    P3177 [HAOI2015]树上染色
    CF835F Roads in the Kingdom/P1399 [NOI2013]快餐店
    P4381 [IOI2008]Island
    P5655 基础数论函数练习题
  • 原文地址:https://www.cnblogs.com/darr/p/5086917.html
Copyright © 2020-2023  润新知