Configuration Objects

Passing a large number of parameters is not convenient. A better approach is to substitute all the parameters with only one and make it an object.

var conf = {

    username: "batman",

    first: "Bruce",

    last: "Wayne"

};

addPerson(conf);

Pros

 Cons

• No need to remember the parameters and their order

• You can safely skip optional parameters

• Easier to read and maintain

• Easier to add and remove parameters

• You need to remember the names of the parameters

• Property names cannot be minified

This pattern could be useful when your function creates DOM elements.

References: 

JavaScript Patterns - by Stoyan Stefanov (O`Reilly)

JavaScript Patterns 4.9 Configuration Objects的更多相关文章

  1. JavaScript Patterns 3.8 Error Objects

    The error objects created by constructors(Error(),  SyntaxError(), TypeError(), and others) have the ...

  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.6 Mix-ins

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

  4. JavaScript Patterns 6.5 Inheritance by Copying Properties

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

  5. JavaScript Patterns 6.4 Prototypal Inheritance

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

  6. JavaScript Patterns 6.2 Expected Outcome When Using Classical Inheritance

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

  7. JavaScript Patterns 5.6 Static Members

    Public Static Members // constructor var Gadget = function (price) { this.price = price; }; // a sta ...

  8. JavaScript Patterns 5.3 Private Properties and Methods

    All object members are public in JavaScript. var myobj = { myprop : 1, getProp : function() { return ...

  9. JavaScript Patterns 5.1 Namespace Pattern

    global namespace object // global object var MYAPP = {}; // constructors MYAPP.Parent = function() { ...

随机推荐

  1. 关联查询 join on 和比较运算符 in

    join on多表之间的关联查询 写法select 字段 from 表1 t join 表2 s on t.字段1 = s.字段1 where 条件: 也可以这么写select 字段 from 表1 ...

  2. 市面上常见的javaEE WEB服务软件

    常见的市面上web服务软件 Tomcat:轻量级的WEB应用程序服务器(开源),开源组织Apache的产品.免费的.支持部分的JavaEE规范.(servlet.jsp.jdbc,但ejb, rmi不 ...

  3. C# RSA 分段加解密

    RSA加解密: 1024位的证书,加密时最大支持117个字节,解密时为128:2048位的证书,加密时最大支持245个字节,解密时为256. 加密时支持的最大字节数:证书位数/8 -11(比如:204 ...

  4. GJM : 数据结构 - 轻松看懂机器学习十大常用算法 [转载]

     转载请联系原文作者 需要获得授权,非法转载 原文作者将享受侵权诉讼 文/不会停的蜗牛(简书作者)原文链接:http://www.jianshu.com/p/55a67c12d3e9 通过本篇文章可以 ...

  5. linux常用命令之查阅文件

    CAT cat – concatenate print files 连续的输出文件内容 用法 cat [-nbA] file 选项 -n line number 输出行号 -b line number ...

  6. Koala – 开源的前端预处理器语言图形编译工具

    koala 是一个前端预处理器语言图形编译工具,支持 Less.Sass.Compass.CoffeeScript,帮助 Web 开发者更高效地使用它们进行开发.跨平台运行,完美兼容 Windows. ...

  7. 极富创意的3D文件夹切换效果

    今天分享的是一个极富创意的文件夹切换效果.这个案例使用CSS 3动画实现了一个3D的平行六面体旋转效果.点击顶部的3个按钮可以旋转并切换.另外,每个六面体本身是一个文件夹,点击后可以展开查看里面的详情 ...

  8. swift学习笔记之-方法部分

    //方法部分 import UIKit //方法(Methods) /*方法是与某些特定类型相关联的函数,类.结构体.枚举都可以定义实例方法 实例方法(Instance Methods): 1.属于某 ...

  9. NavigationBar隐藏后,返回时表现不完美

    是这样的,app首页头部可能要自定义,所以选择把NavigationBar隐藏,所以在viewWillAppear时这样写: self.navigationController?.setNavigat ...

  10. ae显示标注

    //添加标注,比TextElment功能更强大 public static void ToAddAnnotate(ILayer layer, string fieldName) { IGeoFeatu ...