CommonJS规范的简单使用
作者:互联网
//定义和暴露模块
module.exports = {
foo() {
console.log("module1 foo() is called")
}
}
//定义和暴露模块
module.exports = function () {
console.log("module2 function is called")
}
//定义和暴露模块
exports.foo = function () {
console.log("module3 foo is called")
}
exports.bar = function () {
console.log("module3 foo is called")
}
---------------------------------------------app.js
//模块的导入
let module1 = require("./modules/module1")
let module2 = require("./modules/module2")
let module3 = require("./modules/module3")
module1.foo()
module2()
module3.foo()
module3.bar()
标签:CommonJS,exports,log,module3,规范,module2,简单,console,foo 来源: https://www.cnblogs.com/lceihen/p/14454763.html