This is about multiple assignment in JS. Well, it's actually about destructuring assignment, but potato, potato.
Hopefully by now we all know that it can be done with arrays.
What I didn't know is that it can also be done using objects.
This mostly makes sense now that I know it works, I was just a bit surprised. The syntax is strange, but it's oddly satisfying (and follows from the assignment from an array).
Turns out this works for nested objects too…
Just keep in mind the same rules for object references applies. If I change
obj2.foo.dude, that changes
And last but not least, we can also access values directly with nested objects.
obj2.foo.dude here will have no effect on
Add this to the list of cool things that have been implemented in JS 1.6, 1.7, and 1.8, but yet still aren't available in all browsers (sigh). Generators, Iterators, array comprehensions, block scoping with
let… all cool things that are used regularly within the Firefox codebase.