Javascript 什么是双箭头功能?

Javascript 什么是双箭头功能?,javascript,typescript,arrow-functions,Javascript,Typescript,Arrow Functions,什么是“让x=something1=>something2=>something3” 我有这个代码,但我无法理解它的作用 const myReducers = {person, hoursWorked}; const combineReducers = reducers => (state = {}, action) => { return Object.keys(reducers).reduce((nextState, key) => { nextState[ke

什么是“让x=something1=>something2=>something3”

我有这个代码,但我无法理解它的作用

const myReducers = {person, hoursWorked};
const combineReducers = reducers => (state = {}, action) => {
  return Object.keys(reducers).reduce((nextState, key) => {
    nextState[key] = reducers[key](state[key], action);
    return nextState;
  }, {});
};
完整代码,以备您需要:

//Redux-Style Reducer
const person = (state = {}, action) => {
  switch(action.type){
    case 'ADD_INFO':
      return Object.assign({}, state, action.payload)
    default:
      return state;
  }
}

const infoAction = {type: 'ADD_INFO', payload: {name: 'Brian', framework: 'Angular'}}
const anotherPersonInfo = person(undefined, infoAction);
console.log('***REDUX STYLE PERSON***: ', anotherPersonInfo);

//Add another reducer
const hoursWorked = (state = 0, action) => {
  switch(action.type){
    case 'ADD_HOUR':
      return state + 1;
    case 'SUBTRACT_HOUR':
      return state - 1;
    default:
      return state;
  }
}
//Combine Reducers Refresher

****HERE****
****HERE****
****HERE****

const myReducers = {person, hoursWorked};
const combineReducers = reducers => (state = {}, action) => {
  return Object.keys(reducers).reduce((nextState, key) => {
    nextState[key] = reducers[key](state[key], action);
    return nextState;
  }, {});
};


****
****


/*
This gets us most of the way there, but really want we want is for the value of firstState and secondState to accumulate
as actions are dispatched over time. Luckily, RxJS offers the perfect operator for this scenario., to be discussed in next lesson.
*/
const rootReducer = combineReducers(myReducers);
const firstState = rootReducer(undefined, {type: 'ADD_INFO', payload: {name: 'Brian'}});
const secondState = rootReducer({hoursWorked: 10, person: {name: 'Joe'}}, {type: 'ADD_HOUR'});
console.log('***FIRST STATE***:', firstState);
console.log('***SECOND STATE***:', secondState);
From:

可以使用箭头函数

someParameters => someExpression
那么,这是什么

someParameters => someThing => someThingElse

通过简单愚蠢的“模式匹配”,它是一个箭头函数,其主体(
someExpression
)是

换句话说,它是

someParameters => someOtherParameters => someExpression
这没什么特别的。函数是对象,它们可以从函数返回,无论这些函数是使用箭头还是
function
关键字编写的

要正确阅读这篇文章,你真正需要知道的唯一一件事就是箭头是右关联的

a => b => c === a => (b => c)


注意:箭头函数也可以有一个由语句和单个表达式组成的主体。我特别指的是OP感到困惑的形式。

让x=something1=>something2=>something3与以下内容几乎相同:

x=函数(某物){
返回函数(something2){
归还某物
}

}
它只是一组作为参数传递的函数。我想,顶级函数是在某个时候用你的减缩器映射调用的。你能发送一个链接来解释这一点吗?或者更好地解释你的意思是什么?具体解释什么?ES2015文档/教程中介绍了箭头功能<代码>减少具有正常的功能文档。你在问关于Redux部分的问题吗?这能回答你的问题吗?进程结束时x=something3吗?否。
x
现在是一个函数表达式。如果你调用abc=x()。那么abc会让我们平等一些好的,我明白了。谢谢你的回答,伙计!与redux一起玩得开心:)谢谢你的时间和精彩的回答,但我选择了另一个,因为某种原因,它对我来说更清楚。谢谢你,阿吉安。没关系,我的答案假设你已经知道箭头函数是什么,阿卡什解释说根本没有箭头函数。
a => b => c === a => (b => c)