内部函数如何知道这个参数?

How does the inner function know about this parameter?

我正在学习 Redux-Thunk,我有一个关于 JavaScript 的问题。

我们如何获得调度函数?

function incrementAsync() {
  return dispatch => {
    setTimeout(() => {
      // Yay! Can invoke sync or async actions with `dispatch`
      dispatch(increment());
    }, 1000);
  };
}

它是像 incementAsync()(dispatch) 一样传递的还是来自外部函数?

代码示例来自https://github.com/gaearon/redux-thunk

语法param => action用于定义一个接受一个参数并执行一些操作的匿名函数。

你的情况:

var otherFunction = param => {
   console.log(param);
};

var fun = incrementAsync(); // is a function
fun(otherFunction);

The inner function receives the store methods dispatch and getState as parameters.

你的函数将被像incementAsync()(dispatch, getState)

这样的库使用

你不需要那样做。