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

 

posted @ 2016-10-28 12:29  NOIP/NOI辅导  Views(242)  Comments(0Edit  收藏  举报