ES6 won't destroy an object in pre-declared variables?

It works:

const { foo, bar } = someFunc(); 

So:

 let { foo, bar } = someFunc(); 

But if I try to destroy the already declared variables ...

 let foo = 0; let bar = 0; { foo, bar } = someFunc(); 

then:

Uncaught SyntaxError: Unexpected token =

Is it for design? Is there a workaround other than declaring a temp object to get the value? I do this in a switch / case statement; foo and bar are declared on top and used after the switch. So far I can only do:

 const temp = someFunc(); foo = temp.foo; bar = temp.bar; 
+5
source share

Source: https://habr.com/ru/post/1274669/


All Articles