js中if else switch 条件判断的替代方法
2020-08-19 本文已影响0人
p712long
function condition(test){
return({
cat :function(){console.log('cat');},
dog :function(){console.log('dog');},
zhiqiang : function(){console.log('zhiqiang');}
}[test] || function(){console.log('我是默认值');}
)();
}
condition(); // 我是默认值
condition('dog'); // dog