const vegetableColors = {corn: 'yellow', peas: 'green'};
const {*} = vegetableColors;
console.log(corn);// yellow
console.log(peas);// green
Run Code Online (Sandbox Code Playgroud)
我似乎无法找到或弄清楚如何做到这一点,但我真的以为我以前见过它!:P
注:我使用的是巴贝尔与stage设置为0;
背景:我正试图在JSX中干燥而不是参考this.state或this.props在任何地方.如果数据发生变化,也不必继续为destructure添加属性.