zoukankan      html  css  js  c++  java
  • JavaScript Patterns 4.6 Immediate Object Initialization

    ( {
    
        // here you can define setting values
    
        // a.k.a. configuration constants
    
        maxwidth : 600,
    
        maxheight : 400,
    
        // you can also define utility methods
    
        gimmeMax : function() {
    
            return this.maxwidth + "x" + this.maxheight;
    
        },
    
        // initialize
    
        init : function() {
    
            console.log(this.gimmeMax());
    
            // more init tasks...
    
        }
    }).init(); 

    Usage

    protect the global namespace while performing the one-off initialization tasks. 

    Note

    If you want to keep a reference to the object after it is done, you can easily achieve this by adding return this; at the end of init().

  • 相关阅读:
    推荐Windows下SVN服务器端和客户端工具软件
    QT的一些小知识
    Qt
    Qt
    ADB
    HTTP
    Python
    项目附
    项目
    架构
  • 原文地址:https://www.cnblogs.com/haokaibo/p/Immediate-Object-Initialization.html
Copyright © 2011-2022 走看看