代码优化积累【持续更新】

#判断优化(处理多个选择优化)

//bad
if(condition = 'aa' ||condition = 'bb' || condition = 'cc' ){
    //TODO
}

//good
let Regcondition = /^(aa|bb|cc)$/;
Regcondition.test(condition)

//good
var collection = ['aa','bb','cc'];
collection.includes(condition)

 #

posted @ 2018-09-07 14:10  tangjiao_Miya  阅读(112)  评论(0编辑  收藏  举报