[英]What is the difference between qualified and unqualified imports in the new javascript ES6 module lingo?
I came across this distinction which wasn't explained well in ExploringJS 我遇到了这个在ExploringJS中没有得到很好解释的区别
Qualified and unqualified imports work the same way (they are both indirections)
合格和不合格的进口工作方式相同(它们都是间接的)
What is the distinction and therefore what does this statement mean? 区别是什么,因此该陈述的含义是什么?
var foo = require('a').foo // doesn't work with cyclic dependencies
import {foo} from 'a' // can work with cyclic dependencies*
var a = require('a')
function bar() {
a.foo() // can work with cyclic dependencies*
}
exports.bar = bar
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: 在ES2015中,默认导入也可以是限定导入(尽管有些人不同意),如果它们用作命名空间:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.