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() { ...
随机推荐
- $("").click与onclick的区别示例介绍
Html代码: <script type="text/javascript"> $(function(){ $("#btn4").click(fun ...
- Cursors in MySQL Stored Procedures
https://www.sitepoint.com/cursors-mysql-stored-procedures/ After my previous article on Stored Proce ...
- MySQL Cursor
MySQL Cursor Summary: in this tutorial, you will learn how to use MySQL cursor in stored procedures ...
- WebView的使用及添加进度条
实现的效果比较简单类似于微信打开网页,头部有个进度条显示加载进度 下载地址:http://download.csdn.net/detail/qq_29774291/9666941 1.在安卓端加载一个 ...
- Scalaz(46)- scalaz-stream 基础介绍
scalaz-stream是一个泛函数据流配件库(functional stream combinator library),特别适用于函数式编程.scalar-stream是由一个以上各种状态的Pr ...
- puporwindow
//Java代码private void showPopupWindow(View view) { // 一个自定义的布局,作为显示的内容 View contentView = LayoutInfla ...
- JAVA JDK的动态代理反射实现
动态代理类使用到了一个接口InvocationHandler和一个代理类Proxy ,这两个类配合使用实现了动态代理的功能. 什么是动态代理呢? 普通代理类是指: 给每个具体类写一个代理类,以后要使 ...
- ubuntu 安装配置ssh
1.安装ssh-server sudo apt-get install openssh-server 2.设置管理员密码访问 sudo vim /etc/ssh/sshd_config 将“Permi ...
- ASP.NET登录控件login。
1.Login控件.通常情况下会出现3个核心元素.用户名文本框.密码输入框.提交凭证的按钮. 1>.比较重要的属性:CreateUserText属性:包含站点注册页的链接文本.CreateUse ...
- 如何让C#像JavaScript一样编程
JavaScript是一门动态语言,可以动态的给对象添加属性和方法,非常方便.那么有没有一种方式可以让C#也具备动态添加属性和方法的能力,像Javascript一样进行编程? 下面就介绍一个很不错的框 ...