是否可以导出整个Node.JS
模块并具有以下功能:
- 从另一个模块导入这个模块
- 获取所有
methods
并attributes
设置到此模块中 - 我不想将此代码的任何部分从我的模块包装到函数/类中?
例如,我想创建一个REST.js
具有以下属性和方法的模块:
let a = 10
let b = 20
const funcA = (x) => {
//functionA code
}
const funcB = (x, y) => {
//functionB code
}
这个模块需要使用一些语法导入app.js
,这使我能够使用以下 API(或类似的)来获取属性和使用方法REST.js
:
const REST = require('REST')
//get attributes
console.log(REST.a)
console.log(REST.b)
//use methods
let resA = REST.funcA(10)
let resB = REST.funcB(10, 20)
总而言之,我想知道是否有类似于Python
使用模块的语法。