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!
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- no recursive destructuring
- `import {y} from 'x'` is not the same as `import x from 'x'; const {y} = x`
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.)
1. Import the default export as the name `x`.
2. Import named export `x` as the name `x`.
3. Import all of the named exports under an object named `x`.
4. Import named export `x` as the name `y`.
Your last sentence is like a C dev asking a Java dev why they don’t just compile to x64 and be done with it. It comes across as flippant and will likely attract downvotes.
import org.joda.time.Instant as JodaInstant;
The rest of the weirdness is to make it look like JS destructuring
That class doing that transformation will need to refer to both the Joda and java.time class.
All of those the space of namespaces is global. You can't have 2 modules named math.quaterinions in any of those languages. You can in JavaScript. To put it another way, in order to prevent name clashes in C++/C#/Java you have to know the name of every other project on the planet. If someone uses the same namespace then if you ever need to use those 2 projects together one of them will have to be re-factored.
That problem doesn't exist in modern JavaScript. There are no namespaces. There is just floating references to code.
namespace foo {
class Bar ...
}
In another file declare namespace foo {
class Bar ...
}
Now use both foo.Bar from file 1 and foo.Bar from file 2 in the same project. Aliases don't help with thisDifferent assemblies with different assembly names but same namespace and class? Just use the fully qualified type name (and alias it for a shorter name).
Single assembly/project and namespace with the same class in multiple files? If you're just spreading out the code then use partial classes, otherwise why would you define the same type twice?
C# (and other languages) that use virtual namespaces can do everything that file-based namespaces can do, but also support many more scenarios.
There is one gazillion things that are much more a problem than "namespace conflicts" in packaging and package management.
Including security & code authenticity, parallel multi-version handling, sensibility to side effects, speed, auditing and reproducibility.
And in these domain the JavaScript packaging system generally range from being 'catastrophic' to 'absolutely terrible'.
If I have to take an example package management system for the world I would certainly quote cargo, Nix, Guix or Spack but certainly not npm which is quite close to what you should really not do for a package manager.
I don't understand why ES-module authors made it that complicated, when they had the chance to introduce a proper module system.
Why did they not just copy Java's system and be done with it.