简体   繁体   English

JS/TS 语法:内部赋值的解构赋值

[英]JS/TS syntax: Destructuring assignment with inner assignment

I just stumbled upon this line of TS code :我只是偶然发现了这行 TS 代码

const { title = item.text } = item;

It seems to be a destructuring assigment but what does the assignment within the curly brackets do?这似乎是一个解构分配,但大括号内的分配有什么作用?

The inner assignment provides a default value :内部赋值提供了一个默认值

In case item.title is undefined title will be assign item.text instead.如果item.title未定义, title将被分配item.text代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM