如何要求模块进行多次导出而不命名所有导出?
我需要从模块中进行大量导出,如下所示:
employee.js
// Some logic goes here
module.exports = {
AvgEmployees,
AvgDailyEmployee,
AvgAbsenceEmployee,
AvgWorkDaysEmpolyee,
...
..
..
};
main.js
const {
AvgEmployees,
AvgDailyEmployee,
AvgAbsenceEmployee,
AvgWorkDaysEmployee,
...
...
...
} = require('src/employee.js');
// Do what's needed with all the imports
// ....
// ...
我导入了 50 多个导入,每次都开始困扰我命名所有进口。
是否可以一次导入所有这些而不具体命名每个?
I'm requiring a lot of exports from a module as follows:
employee.js
// Some logic goes here
module.exports = {
AvgEmployees,
AvgDailyEmployee,
AvgAbsenceEmployee,
AvgWorkDaysEmpolyee,
...
..
..
};
main.js
const {
AvgEmployees,
AvgDailyEmployee,
AvgAbsenceEmployee,
AvgWorkDaysEmployee,
...
...
...
} = require('src/employee.js');
// Do what's needed with all the imports
// ....
// ...
I'm importing more than 50 imports and it starts to bother me every time to name all the imports.
Is it possible to import all of them at once without naming each one specifically ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,像这样:
变量employee是module.exports的值,而
const { ... } = require('src/employee.js');
只是对象解构:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignmentYes, like this:
Variable employee is the value of module.exports and
const { ... } = require('src/employee.js');
is just object destructuring: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment