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 ...
随机推荐
- Direct3D11学习:(二)基本绘图概念和基本类型
转载请注明出处:http://www.cnblogs.com/Ray1024 一.概述 在正式开始学习D3D11之前,我们必需首先学习必要的基础知识. 在这篇文章中,我们将介绍一下Direct3D ...
- 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5636 Accepted: ...
- Servelet面试题
1. Servlet与JSP有什么区别? Servlet和JSP完成的功能是相同的,都可以接收用户的请求,可以对用户进行响应,可以调用业务方法. 不同点在于JSP是在html或者xml中嵌入了Java ...
- 重新想象 Windows 8 Store Apps (63) - 通信: WebSocket
[源码下载] 重新想象 Windows 8 Store Apps (63) - 通信: WebSocket 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 通信 So ...
- C# winform调用浏览器打开页面方法分享,希望对大家有帮助
在很多客户端程序中我们都需要调用浏览器打开网页,这里分享一个可以在我winform程序调用浏览器的方法,测试通过了. 声明:这个方法是上万个用户测试通过的,不是我没有测试通过就拿出来分享,那个是自己搬 ...
- ActiveReports 报表应用教程 (8)---交互式报表之动态过滤
用户可以使用ActiveReports参数 (Parameters)集合把数据提供给报表中的文本框或图表,也可以选择数据的一个子集显示到报表的特定区域,或者是把数据从主报表象子报表传递.用户可以通过三 ...
- jquery ajax 用 data 和 headers 向 java RESTful 传递参数区别
jquery 的 ajax 是非常方便的一个函数,记录一下 $.ajax 生成的 http 报文 一.使用 data 传递参数: $.ajax({ url : "webrs/test/add ...
- Verilog学习笔记基本语法篇(十)········ 常用系统函数
$display 和 $write 任务 格式: $display (p1,p2,...,pn); $write (p1,p2,..,pn); 这两个函数和系统的任务作用是用来输出信息,即将参数p2到 ...
- HTML JavaScript的DOM操作
1.DOM的基本概念 DOM是文档对象模型,这种模型为树模型:文档是指标签文档:对象是指文档中每个元素:模型是指抽象化的东西. 2.Window对象操作 一.属性和方法: 属性(值或者子对象): op ...
- javascript函数中的三个技巧【三】
技巧三: [函数绑定] 在javascript与DOM交互中经常需要使用函数绑定,定义一个函数然后将其绑定到特定DOM元素或集合的某个事件触发程序上,绑定函数经常和回调函数及事件处理程序一起使用,以便 ...