I came across this distinction which wasn't explained well in ExploringJS
Qualified and unqualified imports work the same way (they are both indirections)
What is the distinction and therefore what does this statement mean?
A qualified import allows using functions with the same name imported from several modules, e.g. map from the Prelude and map from Data.
With the help of ES6, we can create modules in JavaScript. In a module, there can be classes, functions, variables, and objects as well. To make all these available in another file, we can use export and import. The export and import are the keywords used for exporting and importing one or more members in a module.
Introduction to ES6 import:The import statement is used to import modules that are exported by some other module. A module is a file that contains a piece of reusable code. The import modules are in strict mode whether it is declared or not.
The import statement makes modular code possible in JavaScript (and also, code reuse and sharing). Without import or a similar mechanism, a developer could only write a JavaScript program as a single program in one file.
Strictly speaking, there's no such thing as qualified/unqualified imports in JavaScrpit. Those terms were used in the book 'Exploring ES6' by Dr. Axel Rauschmayer in the context of cyclic dependencies, and roughly mean:
CommonJS:
var foo = require('a').foo // doesn't work with cyclic dependencies
ES2015:
import {foo} from 'a' // can work with cyclic dependencies*
CommonJS:
var a = require('a')
function bar() {
a.foo() // can work with cyclic dependencies*
}
exports.bar = bar
ES2015:
import * as a from 'a'
export function bar() {
a.foo() // can work with cyclic dependencies*
}
In ES2015 default imports can also be qualified imports (although some people disagree) if they serve as a namespace:
export default {
fn1,
fn2
}
with cyclic dependencies, you can't access imports in the body of a module:
import {foo} from 'a' // 'a' is a cyclic dependency
foo() // doesn't work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With