• 两段关于模块模式的代码


    记性不好,特此记录。
    代码一:
    var Co = (function () {
        function getTypeOf(o) {
            return typeof o;
        }
        function getPrototypeToString(o) {
            return Object.prototype.toString.call(o);
        }
        return {
            GetTypeOf: function (o) {
                return getTypeOf(o);
            },
            GetPrototypeToString: function (o) {
               return getPrototypeToString(o);
            }
        }
    })();

    Co.GetTypeOf(0.23);
    Co.GetTypeOf("test");
    Co.GetTypeOf({});
    Co.GetTypeOf([]);
    Co.GetTypeOf(/abc/gi);
    Co.GetTypeOf(true);
    //------------------华丽分割线--------------------
    Co.GetPrototypeToString(0.23);
    Co.GetPrototypeToString("test");
    Co.GetPrototypeToString({});
    Co.GetPrototypeToString([]);
    Co.GetPrototypeToString(/abc/gi);
    Co.GetPrototypeToString(true);

    代码二:
    //单例
    var singleton = (function () {
        var instance;
        function init() {
            function privateMethod() {
                console.log("privateMethod.");
            }
            var privateVariable = "privateVariable.";
            var privateRandomNum = Math.random();
            return {
                //publicMethod: privateMethod,
                publicMethod: function () {
                    privateMethod();
                },
                publicProperty: "publicProperty.",
                getRandomNum: function () {
                    return privateRandomNum;
                }
            }
        }
        return {
            getInstance: function () {
                if (!instance) {
                    instance = init();
                }
                return instance;
            }
        }
    })();

  • 相关阅读:
    Spring5.2.x04BeanDefinitionMap
    spring配置类解析
    spring5 解析配置类
    分布式唯一id生成器
    电脑变流畅的方法(也是网吧电脑比家里的电脑流畅的原因)
    nginx启动访问
    Win10按f5不能刷新页面 变成了调节亮度怎么办?
    Linux 内核定时器
    Linux 中断下半部工作队列(work queue)
    Linux 虚拟字符设备globalmem
  • 原文地址:https://www.cnblogs.com/zhaow/p/9754461.html
Copyright © 2020-2023  润新知