一个"implicitly export an entire module"如何?

How does one "implicitly export an entire module"?

以下是 a section 来自 MDN 对 JavaScript import 声明的参考(特别强调):

Import a single export from a module

Given an object or value named myExport which has been exported from the module my-module either implicitly (because the entire module is exported) or explicitly (using the export statement), this inserts myExport into the current scope.

import {myExport} from '/modules/my-module.js';

我知道从模块 显式 (使用 export 语句)导出对象或值意味着什么,但如何导出它们隐含地(隐含地没有使用export语句)?导出 "entire module" 是什么意思?

就这样吧

  1. 给定一个名为 myExport 的对象或值,该对象或值已从模块
  2. 中隐式导出(因为导出了整个模块)

  1. 给定一个名为 myExport 的对象或值,该对象或值已从模块中显式导出(使用导出语句)

所以我可以像这样导出对象或函数

// ./modules/my-module.js
export default UserApi = {
  myExport: function() {
   console.log(please make api call)
  }
}


// ./otherfile.js
import {myExport} from '/modules/my-module.js';

我从不显式导出 myExport 但您可以导入 myExport 而无需导入 UserApi 我显式导出

如果我理解正确的话,我认为这个声明的措辞有些混乱。我 认为 他们所说的 "explicitly" 的意思会明确地 命名 ,例如

export { foo };
// or others
export var foo;
export function foo(){}
export class foo {}
export { foo } from "./foo.js";

隐含地 将是一个未明确命名的,例如

export * from "./foo.js";

然后在哪里做

import { foo } from "./mod.js";

只要 modfoo.js 文件中的 re-exporting foo 就可以工作。