简体   繁体   中英

List all exports in ES6 Module syntax

In CommonJS, one can get all exported properties like so:

module.exports.foo = 1234;
module.exports.bar = 5678;
console.log(module.exports); // <-- The variable `exports`/`module.exports` holds an object
// :)

How can I do the equivalent with ES6 module syntax?

export const foo = 1234;
export const bar = 5678;
console.log(module.exports); // <-- Correctly holds the keys/export names, but not their values
// :(

ES modules have

import * as ModuleObj from "./foo";

to import a namespace object containing all of the exports of a module.

For the usecase of module.exports , you can have the module import itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM