1.定义student模块,teacher模块
function add(student){ console.log('add student:'+student); } exports.add=add; function add(teacher){ console.log('add teacher:'+teacher); } exports.add=add;
2.定义kclass模块
//引入student模块 var student=require('./student'); //引入teacher模块 var teacher=require('./teacher.js'); function add(teachername,students){ teacher.add(teachername); students.foreach(function(item,index){ student.add(item); }); } //向模块对象,注册方法 exports.add=add;
3.定义启动模块 index.js
var class1=require('./kclass.js'); class1.add('高一班',['张三','李四']);
运行结果:
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
vue下拉至页面底部立刻加载数据源生js实现哈夫曼编码步骤详解
以上就是nodejs模块使用步骤详解的详细内容。
