NodeJS(模块化)

模块化:

module1.js
function test01(){
console.log(“module1-test1”);
}
function test02(){
console.log(“module1-test2”);
}
module.exports = {
“test1”:test01,
“test2”:test02
}

module2.js
function test01(){
console.log(“module2-test1”);
}
function test02(){
console.log(“module2-test2”);
}
exports.test1 = test01;
exports.test2 = test02;

test.js
var module1 = require(“./module1.js”);
var module2 = require(“./module2.js”);
module1.test1();
module2.test1();

猜你喜欢

转载自blog.csdn.net/weixin_41220720/article/details/81630352