JavaScript Patterns 2.6 switch Pattern
Principle
• Aligning each case with switch(an exception to the curly braces indentation rule).
• Indenting the code within each case.
• Ending each case with a clear break;.
• Avoiding fall-throughs (when you omit the break intentionally). If you're absolutely convinced that a fall-through is the best approach, make sure you document such cases, because they might look like errors to the readers of your code.
• Ending the switch with a default: to make sure there's always a sane result even if none of the cases matched.
var inspect_me = 0,
result = ''; switch (inspect_me) {
case 0:
result = "zero";
break;
case 1:
result = "one";
break;
default:
result = "unknown";
}
JavaScript Patterns 2.6 switch Pattern的更多相关文章
- JavaScript Patterns 5.8 Chaining Pattern
Chaining Pattern - Call methods on an object one after the other without assigning the return values ...
- JavaScript Patterns 5.5 Sandbox Pattern
Drawbacks of the namespacing pattern • Reliance on a single global variable to be the application’s ...
- JavaScript Patterns 5.4 Module Pattern
MYAPP.namespace('MYAPP.utilities.array'); MYAPP.utilities.array = (function () { // dependencies var ...
- JavaScript Patterns 5.1 Namespace Pattern
global namespace object // global object var MYAPP = {}; // constructors MYAPP.Parent = function() { ...
- JavaScript Patterns 4.2 Callback Pattern
function writeCode(callback) { // do something... callback(); // ... } function introduceBugs() { // ...
- JavaScript Patterns 4.8 Function Properties - A Memoization Pattern
Gets a length property containing the number of arguments the function expects: function func(a, b, ...
- 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.5 Inheritance by Copying Properties
Shallow copy pattern function extend(parent, child) { var i; child = child || {}; for (i in parent) ...
随机推荐
- Functions of the call stack
https://en.wikipedia.org/wiki/Call_stack#STACK-FRAME As noted above, the primary purpose of a call s ...
- Python学习笔记(1)对象类型
强制转换字符串函数str 如果我们求2的一百万次方是多少那么我们可以 print(2**1000000) 如果我们要求2的一百万次方有多少位那么我们可以用str函数强制转换成字符串然后len函数计算 ...
- 动态 SQL(2)
前面我们学习了使用动态 SQL 的 if.where.trim元素来处理一些简单查询操作,但对于一些 SQL 语句中含有 in 条件,需要迭代条件集合来生成的情况,我们就需要使用 foreach 标签 ...
- C++ <queue>用法
C++队列可以不需要自己写,有现成的模版类 头文件: #include <queue> #include <iostream> using namespace std; (之前 ...
- [bzoj2141][排队] (分块大法好)
Description 排排坐,吃果果,生果甜嗦嗦,大家笑呵呵.你一个,我一个,大的分给你,小的留给我,吃完果果唱支歌,大家乐和和.红星幼儿园的小朋友们排起了长长地队伍,准备吃果果.不过因为小朋友们的 ...
- 浅谈href=与href=javascript_void(0)的区别
"#"包含了一个位置信息.默认的锚点是#top 也就是网页的顶端.而javascript:void(0) 仅仅表示一个死链接,这就是为什么有的时候页面很长,浏览链接明明是#可是跳 ...
- Cow Sorting POJ 3270 & HDU 2838
题目网址:http://poj.org/problem?id=3270 题目大意是:一串无序的数字,要排成增序的数列,可以交换不相邻的数,每交换两个数,sum+这两个数,使得sum最小,求最小的sum ...
- vue.js定义一个一级的路由 ----由浅入深
#### 定义一个路由- 实例化一个路由并设置路由映射表 - 实例化里面第一个参数 routes 路由映射表 - routes 里面参数 - path 路由的路径 - component 路由对应的组 ...
- [K/3Cloud]实现双击列表行后显示具体的某个单据明细。
列表插件重写void ListRowDoubleClick(ListRowDoubleClickArgs e)事件,在事件中处理具体逻辑,具体代码如下 public override void Lis ...
- 小L 的二叉树(洛谷 U4727)
题目背景 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣. 所以,小L当时卡在了二叉树. 题目描述 在计算机科学中,二叉树是每个结点最多有两个子结点的 ...