var o = {p: 42, q: true};
var {p, q} = o;
console.log(p); // 42
console.log(q); // true
Эээ, ну, допустим…
A variable can be assigned its value with destructuring separate from its declaration.
var a, b;
({a, b} = {a: 1, b: 2});
The ( .. ) around the assignment statement is required syntax when using object literal destructuring assignment without a declaration.
{a, b} = {a: 1, b: 2} is not valid stand-alone syntax, as the {a, b} on the left-hand side is considered a block and not an object literal.
However, ({a, b} = {a: 1, b: 2}) is valid, as is var {a, b} = {a: 1, b: 2}
NOTE: Your ( .. ) expression needs to be preceded by a semicolon or it may be used to execute a function on the previous line.
[facepalm.tar.xz] (108 MB)