当前位置:网站首页>Node模块化管理

Node模块化管理

2022-06-21 16:51:00 CupidoZ

require关键字引用其他封装好的js模块 继而实现对js文件做了模块化管理

// 引入模块化的js文件 避免引包之间存在相同引用 产生引用覆盖和调用错误
var moduleA  =require('./a.js')
var moduleB  =require('./b.js')
var moduleC  =require('./c.js')

moduleA.test();
moduleA.to_str('abc');
moduleB();
moduleC();
// module 作为模块方法的管理方式
// 管理多个方法的时候可以将引入对象变成对象数组保存方法别名
// 两种写法
// module.exports = {
    
// test:test,
// to_str:to_str
// }
exports.test = test;
exports.to_str=to_str;

function test(){
    
    console.log('test.....01')
}

function to_str(str){
    
    return str.toUpperCase()
}


function test(){
    
    console.log('test.....02')
}
module.exports = test
function test(){
    
    console.log('test.....03')
}
module.exports = test
原网站

版权声明
本文为[CupidoZ]所创,转载请带上原文链接,感谢
https://cupido.blog.csdn.net/article/details/125344296