一天,一个业务写了一个判断:
this.routeBlocks.forEach((item, index) => {
if (index === e) {
item.select = true;
} else {
item.select = false;
}
});
看到几行代码,强迫症愈发强烈!
于是,❌删掉了这几行!变成了下面这个样子:
this.routeBlocks.forEach((item, index) => {
index === e && item.select = true;
index === e || item.select = false;
});
emmmm...,代码从 七行 变成了 四行 ,还是很nice!(手动狗头)
出去上了个厕所,一路上就在想:我真特么6b,明天又有东西跟同事吹了😁。这还不得给我涨工资,哈哈哈哈哈哈哈。。。
临近下班,突然灵光乍现,我还能再把刚刚那个代码再缩短一点,那还不得再给我涨3、5个w的工资😜,于是,再次打开编辑器,哐哐哐。。就变成了这个样子:
this.routeBlocks.forEach((item, index) => {
item.select = index === e;
});
提完代码,心里再一次感叹了一句6b🎉,坐等涨工资咯!
哈哈哈哈哈哈,以上内容纯属虚构,主要就是想告诉大家,写代码的时候再多一个心眼,说不定会有更简洁的代码蹦出来喔!😍