使用对象解构的优点
Sometimes an object contains some set of properties, but you want to destructure it changing the names.
有时,一个对象包含一些属性集,但你要解构它改变了名字。
For example some function name does not suit your naming convention, or you already have a variable with that name.
例如,某些函数名称不适合您的命名约定,或者您已经具有该名称的变量。
You can rename one of the fields using this syntax:
您可以使用以下语法重命名字段之一:
const person = {
firstName: 'Tom',
lastName: 'Cruise'
}
const { firstName: name, lastName } = person
name //Tom
lastName //Cruise
翻译自: https://flaviocopes.com/how-to-rename-object-destructuring/
使用对象解构的优点