if else、switch 语句优化方案

1. 三目运算

result = foo ? foo : default

2. 短路表达式

foo && next()

result = foo || default

3. 使用对象替换 switch

const obj = {

a: 1,

b: 2

}

result = obj[key] || default

猜你喜欢

转载自www.cnblogs.com/M1n90/p/12898768.html