与 ES6 模块的混淆
The confusion with ES6 modules
我正在学习 ES6 模块,想了解它在幕后是如何工作的,也就是说,我们调用了两个 js 文件,file1.js 和 file2.js。
我有两个问题,
1.How 把file2变成模块?
如果我们在 file2.js 中使用导出,那么该文件是否将被确定为模块?
2。当 file2.js 成为模块时会发生什么?
file2.js 被包装在幕后的函数中是真的吗?
希望你明白我的意思。
how to turn file2 into a module?
将其作为一个文件加载(例如,通过import
在某处加载)
is it true that if we use export in file2.js then that file will be determined as a module
不,但是如果您不导出任何内容,它就不可能成为有用的模块(除非它是程序的入口点)。
is it true that file2.js get wrapped inside a function behind the scenes?
那将是模块加载器的实现细节(如果您不编写模块加载器,则无需担心)。不过,我不希望任何模块加载器(除了那些转换为 ES5 的模块加载器)能做到这一点。
我正在学习 ES6 模块,想了解它在幕后是如何工作的,也就是说,我们调用了两个 js 文件,file1.js 和 file2.js。
我有两个问题,
1.How 把file2变成模块?
如果我们在 file2.js 中使用导出,那么该文件是否将被确定为模块?
2。当 file2.js 成为模块时会发生什么?
file2.js 被包装在幕后的函数中是真的吗?
希望你明白我的意思。
how to turn file2 into a module?
将其作为一个文件加载(例如,通过import
在某处加载)
is it true that if we use export in file2.js then that file will be determined as a module
不,但是如果您不导出任何内容,它就不可能成为有用的模块(除非它是程序的入口点)。
is it true that file2.js get wrapped inside a function behind the scenes?
那将是模块加载器的实现细节(如果您不编写模块加载器,则无需担心)。不过,我不希望任何模块加载器(除了那些转换为 ES5 的模块加载器)能做到这一点。