Warum wirft die Objektzerstörung einen Fehler aus, wenn kein varSchlüsselwort davor steht?
{a, b} = {a: 1, b: 2};
wirft SyntaxError: expected expression, got '='
Die folgenden drei Beispiele funktionieren ohne Probleme
var {a, b} = {a: 1, b: 2};
var [c, d] = [1, 2];
[e, f] = [1, 2];
Bonusfrage: Warum brauchen wir keine varfür die Array-Destrukturierung?
Ich bin auf das Problem gestoßen, so etwas zu tun
function () {
var {a, b} = objectReturningFunction();
// Now a and b are local variables in the function, right?
// So why can't I assign values to them?
{a, b} = objectReturningFunction();
}