JavaScript Patterns 4.9 Configuration Objects
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的更多相关文章
- JavaScript Patterns 3.8 Error Objects
The error objects created by constructors(Error(), SyntaxError(), TypeError(), and others) have the ...
- 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.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.2 Expected Outcome When Using Classical Inheritance
// the parent constructor function Parent(name) { this.name = name || 'Adam'; } // adding functional ...
- JavaScript Patterns 5.6 Static Members
Public Static Members // constructor var Gadget = function (price) { this.price = price; }; // a sta ...
- JavaScript Patterns 5.3 Private Properties and Methods
All object members are public in JavaScript. var myobj = { myprop : 1, getProp : function() { return ...
- JavaScript Patterns 5.1 Namespace Pattern
global namespace object // global object var MYAPP = {}; // constructors MYAPP.Parent = function() { ...
随机推荐
- Global和Globals
$a= '1234'; $a = 'abc'; $GLOBAS['b']='123'; function showVar(){ echo $a;//什么也输不出来 echo $b;//123(全局变量 ...
- 高性能的分布式服务框架 Dubbo
我思故我在,提问启迪思考! 1. 什么是Dubbo? 官网:http://dubbo.io/,DUBBO是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及作为SOA服务治理的 ...
- 通过angularJS官方案例快速入门
官方案例-angular-phonecat angularJS官方提供了一个官方案例给大家进行循序渐进的学习,但是如果之前没有接触过node.js以及git的同学这个案例拿着也无从下手-这里就介绍一下 ...
- 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题
B - 大还是小? Time Limit:5000MS Memory Limit:65535KB 64bit IO Format: Description 输入两个实数,判断第一个数大 ...
- MAC下配置WebDav
WebDav完全可以当成一个网络共享的文件服务器使用! # 1. 修改了两个配置文件 # 2. 创建web访问用户的用户名和口令 # 3. 创建了两个目录,并且设置了管理权限 # 切换目录 $ cd ...
- Android 手机卫士4--设置中心显示
1,自定义属性 SettingActivity.java package com.itheima.mobilesafe74.activity; import com.itheima.mobilesaf ...
- Hibernate(七)__多对一 、一对多、 一对一、多对多
1.many-to-one 以学生和部门之间的关系为例: Department.hbm.xml <?xml version="1.0" encoding="utf- ...
- vsftp "上传 553 Could not create file"
我在LINUX下VSftp建立一个FTP服务器,但从WINDOWS使用FTP时,无法上传也无法下载!出错如下 ftp>; ls 200 PORT command successful. Cons ...
- 小白的CSS基础学习
CSS定义: CSS全称为“层叠样式表 (Cascading Style Sheets)”,它主要是用于定义HTML内容在浏览器内的显示样式. CSS代码语法: css样式选择组成部分:选择符+声明( ...
- Eclipse spket插件 内置js文件
这一篇将怎么在spket内置js文件,而不用用户自己去添加. 1. 在开发的Eclipse的 运行配置将下面几个插件勾选上. 2. 在org.eclipse.ui.startup拓展里执 ...