简体   繁体   English

ES6这是三重箭头的语法是什么

[英]ES6 what is this triple fat arrow syntax

Ran into some code that looks like the following: 运行一些类似于以下内容的代码:

return store => next => action => {
    switch(action.type) {
    ...
    default:
      return next(action)
};

The entire sample is here: https://exec64.co.uk/blog/websockets_with_redux/ 整个示例在这里: https : //exec64.co.uk/blog/websockets_with_redux/

What is the triple arrow syntax here? 三重箭头的语法是什么? I'm familiar with arrow functions, but I've never seen more than one used before to define a function. 我熟悉箭头功能,但我从未见过使用过一个以上的箭头定义函数。

It is an arrow function with argument store which returns another arrow function with argument next which returns another one with argument action . 它与参数箭头功能store与参数返回另一个箭头功能next将返回一个又一个带有参数action Analogy with regular functions would be: 与常规函数的类比为:

return function (store) {
  return function(next) {
    return function(action) {
      switch(action.type) {
      ...
      default:
        return next(action)
    }
  }
}

Just to notice that this syntax: 只是要注意这个语法:

const myFunction = someParam => someValue

is shorthand for: 是以下内容的简写:

const myFunction = someParam => {
  return someValue
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM