JavaScript语法说明 - return {... state};

时间:2017-01-28 08:11:39

标签: javascript

尝试学习redux&反应,目前正在消化本教程:https://thinkster.io/tutorials/learn-redux/

现在,我找到了这段代码

const defaultState = { checked: false };
const reducer = function(state = defaultState, action) {
  switch (action.type) {
    case 'TOGGLE':
      return { ...state, checked: !state.checked };
  }
  return state;
};
const store = createStore(reducer);

我需要对此行说明:return { ...state, checked: !state.checked };

...state做了什么?它是ECMA 2015的新功能吗?

更新

我不认为这个问题与What does the three dots in react do?

重复

区别在于What does the three dots in react do?约为JSX spread attributes,而我的问题是ECMAScript spread operator

好吧,不要试图保持防守,但我认为这两者是不同的。

但不知怎的,我在What does the three dots in react do?

中得到了我的问题的答案

感谢mplungjan指出后一个问题:)

0 个答案:

没有答案