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?
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?
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
© 2022 - 2024 — McMap. All rights reserved.