Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one "implicitly export an entire module"?

The following is a section from MDN's reference on the JavaScript import statement (with added emphasis):

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';

I know what it means for an object or value to have been exported from a module explicitly (using the export statement), but how can they be exported implicitly (impliedly without using an export statement)? What does it mean for an "entire module" to be exported?

like image 933
eggyal Avatar asked Nov 06 '22 17:11

eggyal


1 Answers

I think the wording on this statement is somewhat confusing, assuming I understand it correctly. I think what they mean by "explicitly" would be explicitly named, e.g.

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

whereas implicitly would be one that is not explicitly named, like

export * from "./foo.js";

where then doing

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

would work as long as mod is re-exporting foo from the foo.js file.

like image 193
loganfsmyth Avatar answered Nov 14 '22 03:11

loganfsmyth