私は5つのオブジェクトを返す関数を持っています。const
とそのうちの1つをlet
を使って4つ宣言したいと思います。私が望んでいた場合は、すべてのオブジェクトは、私が何ができるconst
を使用して宣言:複数の変数タイプを持つES6の構造化代入
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には記載されていません。
よく 'const {thing1、...} = results;を実行してください。 let {thing5} = results; '? – Bergi