4 ms·
As someone who only occasionally uses JavaScript, module imports are really confusing. Often, I want to do import * as mymodule from './mymodule' Namely,
by captainmuon 9y ago
As someone who only occasionally uses JavaScript, module imports are really confusing. Often, I want to do
import * as mymodule from './mymodule'
Namely, treat the whole module as one thing, and give it a name. It would be great if you could do that without specifying the name manually, e.g. like "import mymodule" in Python.
The other times, I do:
import SingleClass from './singleclass'
# or
import {SingleClass} from './singleclass'
Its rather rare that I want a handfull of single things from a module - either one or all (all can mean "one object that has everything" or "all functions and constants in one wrapper", depending on how stuff is exported). The only time I need the `import {a,b,c} from './utils'` syntax is usually with a grab-bag util function module.
You get used to it, but I sometimes wish things were more like Python.
- deleted 9y ago[deleted]
- jmcdiesel 9y agoThere is a reason for that, though. There is no reason to import what you don't need. This is why wildcard imports are generally frowned upon in most development teams. (I say most, thats unqualified, of course, but from my experience, its always been a part of the code standards) Your code is much more readable and clear when you are explicit about what you are importing.
- emerongi 9y ago"module.doSomething()" is more explicit than "doSomething()"