在 CommonJS 中,可以通过以下方式获取所有导出的属性:
module.exports.foo = 1234;
module.exports.bar = 5678;
console.log(module.exports); // <-- The variable `exports`/`module.exports` holds an object
// :)
如何使用ES6模块语法实现相同的功能?
export const foo = 1234;
export const bar = 5678;
console.log(module.exports); // <-- Correctly holds the keys/export names, but not their values
// :(
exports
对象(如果在ES6中存在这样的东西)。为了简单起见,我保持问题简短。 - 3x071c