更新时间:2023-08-25 23:00:58
不,这是不可能的。
(免责声明:您的语法有效并且同时进行解构和返回,但它相当于
({ id, name, price } = newItem); // assigns global variables
return newItem;
这可能不是你想要的)
要做什么你想要(我假设是创建一个新对象),你需要使用对象文字(可能使用简写属性表示法)。另请参阅使用ES 6中的对象获取某些属性的单行程序:
To do what you want (which I assume is creating a new object), you need to use an object literal (potentially with shorthand property notation). See also One-liner to take some properties from object in ES 6:
const mapStateToProps = ({newItem: {id, name, price}}) => ({id, name, price});