JavaScript Patterns 2.6 switch Pattern
2014-05-21 22:03 小郝(Kaibo Hao) 阅读(282) 评论(0) 编辑 收藏 举报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"; }
作者:小郝
出处:http://www.cnblogs.com/haokaibo/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://www.cnblogs.com/haokaibo/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。