es6 代码片段理解

代码片段理解:

 1 [INCREMENT]: (state, action) => {
 2     const { payload: { id } } = action
 3 
 4     //because payload contains the id and we already know that we are about
 5     //to increment the value of that id, we modify only that value by one
 6 
 7     return {
 8       ...state,
 9       counters: {
10         ...state.counters,
11         [id]: state.counters[id] + 1
12       }
13     }
14   },

line 2:

const { payload: { id } } = action
相当于: id = action.payload.id

line 8 - 10:

{
 8       ...state,
 9       counters: {
10         ...state.counters,
11         [id]: state.counters[id] + 1
12       }
13     }

是表达:state.counter[id] =  state.counters[id] + 1

NOI-001—《C++编程及竞赛训练》 NOI-002—《普及组竞赛强化训练课程》 NOI-003—《初级算法课程》
原文地址:https://www.cnblogs.com/fphuang/p/6007325.html