JS / TS语法:使用内部分配破坏结构分配

问题描述 投票:0回答:1

我偶然发现this line of TS code

const { title = item.text } = item;

似乎是destructuring assigment,但是大括号内的分配有什么用?

javascript typescript ecmascript-6 syntax
1个回答
1
投票

内部分配提供一个default value

如果未定义item.title,将改为分配title

© www.soinside.com 2019 - 2024. All rights reserved.