[英]Equal sign inside object destructuring curly braces
I saw this statement in Graphql directive definition:我在 Graphql 指令定义中看到了这个语句:
const { resolve = defaultFieldResolver } = field;
I know the part const { resolve } = field;
我知道部分
const { resolve } = field;
means getting resolve
property of the field
object out and storing it in a local variable resolve
.意味着获取
field
object 的resolve
属性并将其存储在局部变量resolve
中。 But what I'm coming across for the first time is the = defaultFieldResolver
part.但我第一次遇到的是
= defaultFieldResolver
部分。 What does the equal sign do here?等号在这里做什么? I've done a thorough google search but maybe I'm not aware of the right keyword to search or this is probably something new.
我已经完成了彻底的谷歌搜索,但也许我不知道要搜索的正确关键字,或者这可能是新事物。
Here's the link of the article where I saw this. 这是我看到这个的文章的链接。
Thanks a bunch.谢谢一堆。
That means if field
contains a resolve
property, extract it:这意味着如果
field
包含resolve
属性,请提取它:
const defaultFieldResolver = 'defaultFieldResolver'; const field = { resolve: 'resolve' }; const { resolve = defaultFieldResolver } = field; console.log(resolve);
If field
doesn't contain a resolve
property, assign defaultFieldResolver
to the resolve
variable instead.如果
field
不包含resolve
属性,请将defaultFieldResolver
分配给resolve
变量。
const defaultFieldResolver = 'defaultFieldResolver'; const field = {}; const { resolve = defaultFieldResolver } = field; console.log(resolve);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.