两个紧挨着的粗箭头

5 浏览
0 Comments

两个紧挨着的粗箭头

这个问题已经在这里有了答案

JavaScript中多个箭头函数是什么意思?

那么下面代码中这些胖箭头是做什么用的?如果它们不是两个,我就能够理解了!

export default function clientMiddleware(client) {
  return ({dispatch, getState}) => {
    // ******** starts here **********
    return next => action => {
    // ******** ends here **********
      if (typeof action === 'function') {
        return action(dispatch, getState);
      }
      const { promise, types, ...rest } = action; // eslint-disable-line no-redeclare
      if (!promise) {
        return next(action);
      }
      const [REQUEST, SUCCESS, FAILURE] = types;
      next({...rest, type: REQUEST});
      const actionPromise = promise(client);
      actionPromise.then(
        (result) => next({...rest, result, type: SUCCESS}),
        (error) => next({...rest, error, type: FAILURE})
      ).catch((error)=> {
        console.error('MIDDLEWARE ERROR:', error);
        next({...rest, error, type: FAILURE});
      });
      return actionPromise;
    };
  };
}

这段代码的等价物是什么?

value => value2 => {
  // some code
}

admin 更改状态以发布 2023年5月23日
0
0 Comments

这基本上是一个返回箭头函数的箭头函数。你可以更清晰地书写它:

(value) => {
    return (value2) => {
        // some code
    };
}

这种语法是可能的,因为在不加括号 {...} 的情况下,简写的箭头函数语法将返回在体槽中给定的值

0