条件判断
Prev Chapter 9. 性能调优的最佳实践 Next

条件判断

// 土办法
if (type == 'foo' || type == 'bar') { ... }

// 先进经验是
if (/^(foo|bar)$/.test(type)) { ... }

// 应用对象属性查找
if (({ foo : 1, bar : 1 })[type]) { ... }

Copyright Rebecca Murphey, released under the Creative Commons Attribution-Share Alike 3.0 United States license.


Prev Up Next
变量定义 Home 别把 jQuery 当作黑盒子