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().
JavaScript Patterns 4.6 Immediate Object Initialization的更多相关文章
- JavaScript Patterns 5.7 Object Constants
Principle Make variables shouldn't be changed stand out using all caps. Add constants as static prop ...
- 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 ...
- JavaScript Patterns 6.7 Borrowing Methods
Scenario You want to use just the methods you like, without inheriting all the other methods that yo ...
- JavaScript Patterns 6.6 Mix-ins
Loop through arguments and copy every property of every object passed to the function. And the resul ...
- JavaScript Patterns 6.5 Inheritance by Copying Properties
Shallow copy pattern function extend(parent, child) { var i; child = child || {}; for (i in parent) ...
- JavaScript Patterns 6.4 Prototypal Inheritance
No classes involved; Objects inherit from other objects. Use an empty temporary constructor function ...
- JavaScript Patterns 6.3 Klass
Commonalities • There’s a convention on how to name a method, which is to be considered the construc ...
- JavaScript Patterns 6.2 Expected Outcome When Using Classical Inheritance
// the parent constructor function Parent(name) { this.name = name || 'Adam'; } // adding functional ...
- JavaScript Patterns 5.8 Chaining Pattern
Chaining Pattern - Call methods on an object one after the other without assigning the return values ...
随机推荐
- cocos2dx-3.x 导出自定义类到 lua 过程详解
转载请注明出处:http://www.cnblogs.com/Ray1024 一.简介 最近正在学习cocos2d中的lua游戏开发,因为lua开发的热更新特性,大家开发游戏好像都会优先选择lua作为 ...
- ASP.NET身份验证
Asp.net的身份验证有有三种,分别是"Windows | Forms | Passport",其中又以Forms验 证用的最多,也最灵活. Forms 验证方式对基于用户的验证 ...
- Gradle学习系列之十——自定义Plugin(本系列完)
在本系列的上篇文章中,我们讲到了如何自定义Task类型,在本篇文章中,我们将讲到如何自定义Plugin. 请通过以下方式下载本系列文章的Github示例代码: git clone https://gi ...
- MVC知识点02
MVC基础知识详情 1:在MVC中如果要从前台页面(.aspx)获取参数,只需要将其两个页面的参数设置成一样的,这样子MVC中的机制就会自动的将参数的值传到方法中. 2:在MVC中的方法要是两个都是相 ...
- Oracle工程建设行业解决方案
为何选择Oracle工程建设行业解决方案? Oracle为工程建设企业提供一套全面.开放且集成的业务管理软件.服务器和存储解决方案.这些解决方案经过集成设计,能够实现卓越性能,从而优化业务的方方面面. ...
- 怎样计算一个整数的位数&并把每一位上的数字保存下来
用循环来解决~~ M每次除以10, 再用一个变量count来计数,每循环一次 加1,直到这个数除去10后的数小于10 ,count再加1就可以了 实例:整数M=4325, 第一次:4325/10=43 ...
- 重新想象 Windows 8.1 Store Apps (90) - 通信的新特性: 通过 HttpBaseProtocolFilter 实现 http 请求的缓存控制,以及 cookie 读写; 自定义 HttpFilter; 其他
[源码下载] 重新想象 Windows 8.1 Store Apps (90) - 通信的新特性: 通过 HttpBaseProtocolFilter 实现 http 请求的缓存控制,以及 cooki ...
- ActiveReports 报表控件官方中文入门教程 (3)-如何选择页面报表和区域报表
本篇文章将介绍区域报表和页面报表的常见使用场景.区别和选择报表类型的一些建议,两种报表的模板设计.数据源(设计时和运行时)设置.和浏览报表的区别. ActiveReports 报表控件官方中文入门教程 ...
- PHP学习笔记:利用gd库给图片打图片水印
<?php $dst_path = '1.jpg';//目标图片 $src_path = 'logo1.png';//水印图片 //创建图片的实例 $dst = imagecreatefroms ...
- php学习笔记:利用gd库生成图片,并实现随机验证码
说明:一些基本的代码我都进行了注释,这里实现的验证码位数.需要用的字符串都可以再设置.有我的注释,大家应该很容易能看得懂. 基本思路: 1.用mt_rand()随机生成数字确定需要获取的字符串,对字符 ...