首页 > 解决方案 > 这个变量声明表是什么意思?

问题描述

正是这种情况,当你得到一些代码时,它可以工作,但你不知道如何。这个声明方法有什么作用?

const { actions: { createRole, updateRole } = {} } = props;

标签: javascriptreactjs

解决方案


该代码对嵌套对象使用破坏。以下示例可能有助于理解这种新的 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


推荐阅读