javascript - ES6 双箭头参数(即 const update = x => y => { } )

标签 javascript ecmascript-6 currying

<分区>

下面代码中的双箭头参数是什么意思?

const update = x => y => {
   // Do something with x and y
}

与下面的相比有何不同?

const update = (x, y) => {
   // Do something with x and y
}

谢谢!

最佳答案

让我们重写它们“旧式”,第一个是:

const update = function (x) {
  return function(y) {
    // Do something with x and y
  };
};

第二个是:

const update = function (x, y) {
  // Do something with x and y
};

如您所见,它们非常不同,第一个返回“中间”函数,而第二个是具有两个参数的单个函数。

关于javascript - ES6 双箭头参数(即 const update = x => y => { } ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46365288/

相关文章:

javascript正则表达式来测试字母和数字是否存在

javascript - .map() 一个 Javascript ES6 map ?

javascript - 如何在嵌套的 React 组件中传递状态和处理程序

haskell - curry 有什么好处?

javascript - ClearTimeout 不能很好地工作(可能是在第一次定时器触发之前清除时)

javascript - 调整大小、CSS 解决方案或仅使用 Javascript 时绝对 div 重叠兄弟?

javascript - 如何在特定的 Div 上添加 Position Fixed,然后在滚动时删除该类

javascript - 多个 ID 和类共享 AddEventListener

parameters - F#管道第一个参数

typescript - 柯里化(Currying)函数的返回类型