if a edit; else if x1 addx1; else if x2 addx2 else addx3 请帮我把这段js优化一下让他更简洁优雅
可以将 if-else 语句简化为三元运算符,如下:
a ? edit() : x1 ? add(x1) : x2 ? add(x2) : add(x3);
这样可以让代码更加简洁,但是也可能会降低代码的可读性,因此需要在实际场景中权衡取舍。
原文地址: https://www.cveoy.top/t/topic/b3SM 著作权归作者所有。请勿转载和采集!