javascript - 这个变量声明表是什么意思?
问题描述
正是这种情况,当你得到一些代码时,它可以工作,但你不知道如何。这个声明方法有什么作用?
const { actions: { createRole, updateRole } = {} } = props;
解决方案
该代码对嵌套对象使用破坏。以下示例可能有助于理解这种新的 JavaScript 语法(已在 ES6 中引入):
const user = {
id: 339,
name: 'Fred',
age: 42,
education: {
degree: 'Masters'
}
};
const {education: {degree}} = user;
console.log(degree); //prints: Masters
我会推荐以下资源以获取更多示例: https ://medium.com/@pyrolistical/destructuring-nested-objects-9dabdd01a3b8
推荐阅读
- go - 使用 Go 转储 Arangodb 数据库
- r - 同时对两行条件进行子集化
- pyspark - py4j.Py4JException:方法__getstate__([])在pyspark中通过类方法映射时不存在
- ssh - rsync 在管道上通过 SSH 发送时找不到本地目录
- kotlin - 如何构建字段为“var”且可以为“@annotated”的构造函数?
- javascript - html表格到excel不显示英镑货币符号
- ios - 无法为 ios 安装颤振应用程序
- laravel - Vue中如何分离组件?
- mysql-workbench - 如何编辑 code_editor.xml 以启用深色主题?
- javascript - 由于路径错误,Electron 找不到模块