[英]What are these () in ES6 syntax?
I see this code: 我看到以下代码:
const enhance = withHandlers({
signIn: ({ signIn, provider }) => () => signIn(provider)
});
I understand enhance
is a function. 我了解
enhance
功能。 signIn
is also a function, but what's the meaning of the empty ()
in between? signIn
也是一个函数,但两者之间的empty ()
是什么意思? Why can't it just be: 为什么不能只是:
signIn: ({signIn, provider}) => signIn(provider)
No. The ()
is part of the arrow function. 否。
()
是箭头功能的一部分。 It's a function that returns a function. 它是一个返回函数的函数。 Let me break it down:
让我分解一下:
signIn: ({ signIn, provider }) => () => signIn(provider)
^ ^ ^
Destructuring Implicit No argument
assignment return arrow function
for arguments
The property signIn
is a method that takes in an object argument and returns a function which executes signIn(provider)
. signIn
属性是一个接受对象参数并返回执行signIn(provider)
的函数的方法。
Your version: 您的版本:
signIn: ({signIn, provider}) => signIn(provider)
Does not return a function that executes signIn(provider)
, it returns the return value of signIn(provider)
. 不返回执行的函数
signIn(provider)
,它返回的返回值signIn(provider)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.