在使用 JavaScript 时,我们常常要写不少的条件语句。如何将我们的代码写的更加简洁和优雅,是我们需要一直思考的问题。 1. 使用 Array.includes 来处理多重条件 举个栗子 :chestnut:: // 条件语句 function test(fruit) { if (fruit == 'apple' || fruit == 'cherry') { console.log('red'); } } 复制代...
在使用 JavaScript 时,我们常常要写不少的条件语句。如何将我们的代码写的更加简洁和优雅,是我们需要一直思考的问题。 1. 使用 Array.includes 来处理多重条件 举个栗子 :chestnut:: // 条件语句 function test(fruit) { if (fruit == 'apple' || fruit == 'cherry') { console.log('red'); } } 复制代...