// 土办法 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.