Is Javascript’s import syntax semantically wrong?

RMAG news

In JS, if when import a file as a whole, the syntax is
import XXX from ‘./xxx’

But I think this is semantically wrong, because the word from indicates that the thing you are importing is a part of the file, not the file itself.

For example, if A takes a candy from B, then the candy is just a part of B’s belongings, not B himself.

So it should be just import ‘./xxx’, and it is like this in other languages such as Java.

If we need to give it an alias, it is import ‘./xxx’ as xxx.

If it is like this, then when importing parts from a file, we can omit the dereference curly brackets, so it is import XXX from ‘./xxx’ instead of import { XXX } from ‘./xxx’.

In the latter, {} and from are redundant and confusing.

Leave a Reply

Your email address will not be published. Required fields are marked *