let text, value;
if (typeof f == 'string') {
text = value = f;
} else {
let {
text, value
} = f;
}
In questo modo si crea due nuovi Vars (dal else
), se scrivo in questo modo:ES6 destrutturazione, assegnazione dinamica
let text, value;
if (typeof f == 'string') {
text = value = f;
} else {
{
text, value
} = f;
}
ricevo un errore di sintassi. Qual è l'approccio migliore qui?
In alternativa, 'const {text, valore} = (typeof f === 'stringa') ? {text: f, value: f}: f; ' – loganfsmyth