使用es6->Map()结构优化条件语句。

75 阅读1分钟

直接上代码、

const isColor = new Map()

.set('red',function(colorRed){

// 条件成立执行
console.log(colorRed);  // 红色

}) .set('blue',function(){

// ...

}) .set('pink',function(){

//....

})

function test(color){

return isColor.get(color) || ''

}

test('red')('红色');