=>
是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);
};