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的更多相关文章

  1. JavaScript Patterns 5.8 Chaining Pattern

    Chaining Pattern - Call methods on an object one after the other without assigning the return values ...

  2. JavaScript Patterns 5.5 Sandbox Pattern

    Drawbacks of the namespacing pattern • Reliance on a single global variable to be the application’s ...

  3. JavaScript Patterns 5.4 Module Pattern

    MYAPP.namespace('MYAPP.utilities.array'); MYAPP.utilities.array = (function () { // dependencies var ...

  4. JavaScript Patterns 5.1 Namespace Pattern

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

  5. JavaScript Patterns 4.2 Callback Pattern

    function writeCode(callback) { // do something... callback(); // ... } function introduceBugs() { // ...

  6. 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, ...

  7. 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 ...

  8. JavaScript Patterns 6.7 Borrowing Methods

    Scenario You want to use just the methods you like, without inheriting all the other methods that yo ...

  9. JavaScript Patterns 6.5 Inheritance by Copying Properties

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

随机推荐

  1. @objc and dynamic

      @objc and dynamic Objective-C runtime visibility and the depths of dynamic dispatch in the modern ...

  2. 搜索--P1219 N皇后

    题目描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行.每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子. 上面的布局可以用序列2 4 6 1 3 ...

  3. geth搭建以太坊私链及常用操作

    一.下载安装geth客户端 https://www.ethereum.org/ 二.搭建私有链 1.准备创世区块配置文件 要运行私有链,我们就需要定义自己的创世区块,创世区块信息写在一个json格式的 ...

  4. 你相信吗??Python把数字也当做对象!@@@对象,名称绑定,引用计数

    本文学习自:http://blog.csdn.net/yockie/article/details/8474408 1.对象 Python中, 万物皆对象,包括12345等int常量.不信吗??用di ...

  5. 日常操作之如何打开windows注册表

    1.打开注册表:第一步按“win+R”或者点击开始菜单,找到运行,在运行输入框里面输入“regedit”.

  6. 一、ECharts简介

    ECharts,缩写来自Enterprise Charts,商业级数据图表,一个纯Javascript的图表库,可以流畅的运行在PC和移动设备上,兼容当前绝大部分浏览器(IE6/7/8/9/10/11 ...

  7. linux下使用tomcat下载中文文件报404not find

    首先,大神指路:http://bbs.csdn.net/topics/391065011?page=1 相关的一些命令: 查看当前系统字符编码:env locale 查看系统支持的字符编码:local ...

  8. 设置mysql5.7远程连接-----------https://blog.csdn.net/qiyueqinglian/article/details/52778230

    https://blog.csdn.net/qiyueqinglian/article/details/52778230 设置mysql5.7远程连接

  9. pyhthon第一个小脚本——文件备份

    先说说这个脚本的作用:对指定路径的文件进行压缩备份到另一个指定的路径,并且压缩文件的文件名用当时的日期+时间命名. 先是对着<简明Python教程>上的代码敲的,一堆错误,书上给的是lin ...

  10. empty array & Array.from

    empty array bug const duplicationArray = (arr = [], times = 2, debug = false) => { let result = [ ...