本文实例讲述了nodeJS模块简单用法。分享给大家供大家参考,具体如下:
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('高一班',['张三','李四']);
运行结果:
希望本文所述对大家nodejs程序设计有所帮助。