简写条件语句
2021-01-22 本文已影响0人
廖小芝
const actions = new Map([
[{code:'CE0001'},()=>{//to do something }],
[{code:'CE0002'},()=>{}],
[{code:'CE0003'},()=>{}],
[{code:'CE0004'},()=>{}],
[{code:'CE0005'},()=>{}],
[{code:'CE0006'},()=>{}],
...
])
let action = [...actions].filter(([key,value])=>(key.code == code))
action.forEach(([key,value])=>value.call(this))