Skip to content

Commit d0065eb

Browse files
authored
Merge pull request basarat#278 from liukun/patch-1
Object destructuring to existing variables
2 parents aac5331 + d7c06e5 commit d0065eb

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

docs/destructuring.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ var rect = { x: 0, y: 10, width: 15, height: 20 };
2525
// Destructuring assignment
2626
var {x, y, width, height} = rect;
2727
console.log(x, y, width, height); // 0,10,15,20
28+
29+
rect.x = 10;
30+
({x, y, width, height} = rect); // assign to existing variables using outer parentheses
31+
console.log(x, y, width, height); // 10,10,15,20
2832
```
2933
Here in the absence of destructuring you would have to pick off `x,y,width,height` one by one from `rect`.
3034

0 commit comments

Comments
 (0)