zoukankan      html  css  js  c++  java
  • JavaScript设计模式

    // 创建窗体 单例
            var CreateWindow = (function () {
    
                // 设置属性
                function Singleton(option) {
    
                    //设置option变量为接收的参数或者为空(如果没有提供的话)
                    var option = option || {};
                }
    
                // 设置方法
                Singleton.prototype = {
                    constructor: Singleton,
    
                    fn: function() {
                        console.log('fn');
                    }
                };
    
                //实例容器
                var instance;
    
                var _static = {
                    name: 'CreateWindow',
    
                    //获取实例的方法
                    //返回Singleton的实例
                    getInstance: function (args) {
                        if (instance === undefined) {
                            instance = new Singleton(args);
                        }
                        return instance;
                    }
                };
                return _static;
            })();
    
            var cw = CreateWindow.getInstance({});
            cw.fn();
  • 相关阅读:
    poj1087最大流拆点
    3月15上午的函数练习
    3月15
    3月13上午
    3月13
    3月12
    break语句
    3月11
    3月10号
    3月9号
  • 原文地址:https://www.cnblogs.com/sorrowx/p/6972251.html
Copyright © 2011-2022 走看看