请考虑以下代码段
const x = {
name: 'somebody'
};
const { name as somePerson } = x; // Would be awesome to have something like this
答案 0 :(得分:3)
您可以更改Object Property Assignment Pattern [You Don't Know JS: ES6 & Beyond, Chapter 2: Syntax]中的目标:
此处的句法模式为
source: target
(或value: variable-alias
)。
{ name: somePerson }
const x = {
name: 'somebody'
};
const { name: somePerson } = x;
console.log(somePerson);