javascript - 两个肥箭相随

标签 javascript syntax ecmascript-6

<分区>

那么这些粗箭头在下面的代码中做了什么?如果他们不是两个我能理解!

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
}

最佳答案

这基本上是一个返回箭头函数的箭头函数。你可以把它写得更清楚:

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

语法是可能的,因为the shorthand arrow function syntax without enclosing braces {...} returns the value of given in the body slot :

关于javascript - 两个肥箭相随,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37323293/

相关文章:

javascript - 无法访问 typescript 中的全局变量

javascript - 服务器端和后端之间的区别

javascript - 使用 .withSuccessHandler 更改输入按钮的属性

java - 为什么这个简单的java代码不能编译?

javascript - 如何使用搜索框中的搜索词从 ReactJS 中的多个 URL 获取 JSON 数据?

javascript - 在 ES6 中创建多个构造函数

c# - 既触发 javascript 函数又触发 c# 函数的 ASP.NET 事件

javascript - 如何在 JavaScript 中调用原型(prototype)之外的函数?

bash - "plus colon"("+:") 在 shell 脚本表达式中是什么意思?

syntax - F# 创建和填充 FSharpx.Collections.Vector 的语法是什么?