Comment on ES6 in Depth: DestructuringparentComments−loganfsmyth11yYeah, I wish that were handled better too. Since the parser is expecting a statements, it parses it like { a } = 5 As in, a block with just an "a" in it, followed by an assignment to nothing, which throws an syntax error.You can however do ({a} = 5); to make the parser switch to expecting a destructuring pattern instead of an block statement.−dandelany11yWhoops, my last line contains a major typo and should read `{a} = myThing;`. And you've dutifully carried over my typo to your example :DBut regardless, the corrected version of your example: `let a; ({a} = {a:5});` works like a charm and is very handy! Thanks for the tip!
Comments
Yeah, I wish that were handled better too. Since the parser is expecting a statements, it parses it like
As in, a block with just an "a" in it, followed by an assignment to nothing, which throws an syntax error.You can however do
to make the parser switch to expecting a destructuring pattern instead of an block statement.Whoops, my last line contains a major typo and should read `{a} = myThing;`. And you've dutifully carried over my typo to your example :D
But regardless, the corrected version of your example: `let a; ({a} = {a:5});` works like a charm and is very handy! Thanks for the tip!