我有一个返回5个对象的函数,我想使用声明4个对象,并使用声明const
1个对象let
。如果我想要使用声明的所有对象,const
我可以做:
const { thing1, thing2, thing3, thing4, thing5 } = yield getResults();
我当前的解决方法是:
const results = yield getResults();
const thing1 = results.thing1;
const thing2 = results.thing2;
const thing3 = results.thing3;
const thing4 = results.thing4;
let thing5 = results.thing5;
但是我想知道解构分配是否可以让您更优雅地进行此操作。
据我所知,没有在MDN或stackoverflow上提及此问题。
无法执行同时初始化let
和const
变量的解构。但是,const
可以将对的分配简化为另一个分解:
const results = yield getResults()
const { thing1, thing2, thing3, thing4 } = results
let thing5 = results.thing5
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句