Ho una funzione che restituisce 5 oggetti, e vorrei dichiararne 4 usando const
e 1 di loro usando let
. Se avessi voluto tutti gli oggetti dichiarati utilizzando const
ho potuto fare:Assegnazione destrutturazione ES6 con più di una variabile tipo
const { thing1, thing2, thing3, thing4, thing5 } = yield getResults();
mia soluzione attuale è:
const results = yield getResults();
const thing1 = results.thing1;
const thing2 = results.thing2;
const thing3 = results.thing3;
const thing4 = results.thing4;
let thing5 = results.thing5;
Ma mi chiedo se destrutturazione assegnazione ti permette di fare questo più elegante.
Nessuna menzione di questa domanda su MDN o su stackoverflow, per quanto posso vedere.
Beh, basta fare 'const {thing1, ...} = risultati; let {thing5} = risultati; '? – Bergi