( {

    // 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().

JavaScript Patterns 4.6 Immediate Object Initialization的更多相关文章

  1. JavaScript Patterns 5.7 Object Constants

    Principle Make variables shouldn't be changed stand out using all caps. Add constants as static prop ...

  2. JavaScript Patterns 7.1 Singleton

    7.1 Singleton The idea of the singleton pattern is to have only one instance of a specific class. Th ...

  3. JavaScript Patterns 6.7 Borrowing Methods

    Scenario You want to use just the methods you like, without inheriting all the other methods that yo ...

  4. JavaScript Patterns 6.6 Mix-ins

    Loop through arguments and copy every property of every object passed to the function. And the resul ...

  5. JavaScript Patterns 6.5 Inheritance by Copying Properties

    Shallow copy pattern function extend(parent, child) { var i; child = child || {}; for (i in parent) ...

  6. JavaScript Patterns 6.4 Prototypal Inheritance

    No classes involved; Objects inherit from other objects. Use an empty temporary constructor function ...

  7. JavaScript Patterns 6.3 Klass

    Commonalities • There’s a convention on how to name a method, which is to be considered the construc ...

  8. JavaScript Patterns 6.2 Expected Outcome When Using Classical Inheritance

    // the parent constructor function Parent(name) { this.name = name || 'Adam'; } // adding functional ...

  9. JavaScript Patterns 5.8 Chaining Pattern

    Chaining Pattern - Call methods on an object one after the other without assigning the return values ...

随机推荐

  1. SQL Server添加MDW性能监控报表

    10.2 Data Collector与MDW Data Collection功能是SQL SERVER 2005版本提供的数据库监控报表的功能,通过定时地对数据库的语句运行情况,服务器各种资源的监控 ...

  2. Brute Force --- UVA 10167: Birthday Cake

     Problem G. Birthday Cake  Problem's Link:http://uva.onlinejudge.org/index.php?option=com_onlinejudg ...

  3. GitHub Extension for Visual Studio 2.0 is now available

    GitHub Extension for Visual Studio 2.0 is now available We're pleased to announce that version 2.0 o ...

  4. sql跨数据库转移

    结构一样的话insert into 数据库A.dbo.TableAselect * from 数据库B.dbo.TableA 另外:nsert into DDD(字段1,字段2,字段3 .....)( ...

  5. QQ视差特效和ListView侧滑删除

    如图所示是效果图,当向下拉时,图片会被拉出来,松手后恢复.和ListView的侧滑删除   1.视差特效 首先图片是通过addHeaderView加上去的,所以在设置Adapter前先设置一个View ...

  6. jQuery获取Select选择的Text和 Value(转)用时比较方便寻找

    ---恢复内容开始--- jQuery获取Select选择的Text和Value:语法解释:1. $("#select_id").change(function(){//code. ...

  7. 「C语言」C输出hello world!系统发生了什么?

    本篇文章全部摘抄自学长博客供以后学习: http://efraim.me/2015/12/05/tech-linux-2015-12-05/ 排版因与博客园编辑器不同而稍作修改. 输出hello wo ...

  8. Smtp邮件发送系统公用代码整理—总结

    1.前言 a.在软件开发中,我们经常能够遇到给用户或者客户推送邮件,推送邮件也分为很多方式,比如:推送一句话,推送一个网页等等.那么在系统开发中我们一般在什么情况下会使用邮件发送呢?下面我简单总结了一 ...

  9. SAP_Web_Service开发配置

    第一章    SAP创建WS 1.1       概要技术说明 1.2       创建RFC函数 1.3       创建WS 1.4       外部系统访问配置 第二章    SAP调用WS 2 ...

  10. Device Channels in SharePoint 2013

    [FROM:http://blog.mastykarz.nl/device-channels-sharepoint-2013/] One of the new features of SharePoi ...