码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript Patterns 2.6 switch Pattern

时间:2014-05-22 16:15:39      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   c   code   java   

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.

bubuko.com,布布扣
var inspect_me = 0,
result = ‘‘;

switch (inspect_me) {
   case 0:
      result = "zero";
      break;
   case 1:
      result = "one";
      break;
   default:
      result = "unknown";
}
bubuko.com,布布扣

JavaScript Patterns 2.6 switch Pattern,布布扣,bubuko.com

JavaScript Patterns 2.6 switch Pattern

标签:style   class   blog   c   code   java   

原文地址:http://www.cnblogs.com/haokaibo/p/switch-pattern.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!