简体   繁体   English

object 内的等号解构花括号

[英]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.

相关问题 花括号,等号和javascript正则表达式 - Curly braces, equal sign and javascript regular expression 数组解构中的花括号从函数中返回 - Curly braces inside array destructuring in return from a function React 中花括号内的花括号 - Curly braces inside curly braces in React 大括号和过滤器 - 过滤器返回对象,但它转换为{{}}内的字符串 - Curly braces and filters - filter returns object but it gets converted to a string inside {{ }} 大括号内的函数调用 {} - Function invocation inside curly braces {} 应该在哪里使用哪个支架? object 解构时方括号或花括号? 我很想使用上下文但有点困惑 - Which brackest should be used where ? square brackets or curly braces while object destructuring ? I'm tyring to use context but bit confused 谷歌表格中字符串内的美元符号+双花括号(某种变量?) - Dollar sign + double curly braces inside string in google sheets (some kind of variable?) 正则表达式用于匹配函数花括号中的所有内容 - Regex for matching everything inside a function curly braces 使用正则表达式在双花括号内获取值 - Get values inside double curly braces with regex JSX 花括号内的 if 和 else if 语句 - if and else if statement inside JSX curly braces
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM