Reputation: 125995
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 modulemy-module
either implicitly (because the entire module is exported) or explicitly (using theexport
statement), this insertsmyExport
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?
Upvotes: 5
Views: 830
Reputation: 161617
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.
Upvotes: 2
Reputation: 1009
lets make it this way
or
so i can export an object or func like this
// ./modules/my-module.js
export default UserApi = {
myExport: function() {
console.log(please make api call)
}
}
// ./otherfile.js
import {myExport} from '/modules/my-module.js';
i never explicitly export myExport
but you can import myExport
without importing UserApi
which i explicitly export
Upvotes: -1