CommonJS模块导出方式对比
module.exports
// math.js
function add(a, b) {
return a + b
}
module.exports = add // 导出一个函数// main.js
const add = require('./math.js')
console.log(add(2, 3)) // 5exports
总结
Last updated
Was this helpful?