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('高一班',['张三','李四']);运行结果:
相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!
推荐阅读:
JS怎样使用前后端同构
下载本文