Re:Node Modules at War: Why CommonJS and ES Modules Can’t Ge...
by fireattack on Thursday August 06, 2020 @03:17AM
(#24068799)
I think people (like the author of this article) should explain the syntax of destructuring assignment {x} briefly to make it make more sense for the unfamiliar.
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Re:Node Modules at War: Why CommonJS and ES Modules Can’t Ge...
by Kinrany on Thursday August 06, 2020 @07:56AM
(#24070138)
This looks similar to detructuring assignment, but it isn't:
- no recursive destructuring
- `import {y} from 'x'` is not the same as `import x from 'x'; const {y} = x`
Re:Node Modules at War: Why CommonJS and ES Modules Can’t Ge...
by fireattack on Thursday August 06, 2020 @08:36AM
(#24070343)
Thanks for pointing it out, didn't know that.
But I think your second point is more to do with the fact `import` by default imports `default` instead of the whole thing.
If you use import * as x from 'x'; then `const {y} = x;` works.
I personally will consider it is `import from` being different from a typical object instead of {x} here being different from typical destructuring assignment (by that I mean they still follow the same pattern; not necessarily say they're the same thing.)
2. Get the exported value x
3. Get all exported values and call the object x
4. Get the exported value x and call it y
They're all different because they allow you to do different things, and fairly readable.
Edit: Just realised dimgl said the same 45min ago, my bad!