首页 > 网站 > WEB开发 > 正文

JavaScript Patterns 4.6 Immediate Object Initialization

2024-04-27 14:22:42
字体:
来源:转载
供稿:网友

javaScript Patterns 4.6 Immediate Object Initialization

2014-06-12 23:58 by 小郝(Kaibo Hao), ... 阅读, ... 评论, 收藏, 编辑
( {    // 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().


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表