=>
是es6语法中的arrow function
(x)=>x+6
相当于
function(x){
return x+6;
}
快捷写法,不通过function
关键字创建函数,还可省略return
关键字.同时,箭头函数还可以继承当前上下文的this
关键字。
[1,2,3].map(x => x+1); //[2,3,4]
等同于
[1,2,3].map((function(x) {
return x+1;}).bind(this));
const add = (state, { payload }) => {
return state.concat(todo);
};
等同于
const add = function(state,{payload}){
return state.concat(todo);
};