销毁和重命名属性 [英] Destructuring and rename property

查看:108
本文介绍了销毁和重命名属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

const a = {
 b: {
  c: 'Hi!'
 }
};

const { b: { c } } = a;

在这种情况下是否可以重命名b?我想获取c并重命名b.

Is it possible rename b in this case? I want get c and also rename b.

推荐答案

您可以通过重命名来进行销毁,并采用相同的属性进行销毁.

You could destructure with a renaming and take the same property for destructuring.

const a = { b: { c: 'Hi!' } };
const { b: formerB, b: { c } } = a;

console.log(formerB)
console.log(c);

这篇关于销毁和重命名属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆