function name(name){
return name;
}
module.exports = name;
// 支持两个及以上函数
module.exports = {
name:function(name){
return name;
},
age:function(age){
return age;
}
}
调用
var name = out.name("聂伟博")
var age = out.age("15")
var name = out['name']("李丽艳")
var age = out['age']("18")
调用模块
demo.js
function boy(name,age,sex){
this.name = name;
this.age = age;
this.sex = sex;
this.say = function(){
console.log(this.name+"说他今年"+this.age+"他是"+this.sex);
}
}
module.exports = boy;
teacher.js
var boy = require("./demo.js");
function teacher(name,age,sex){
boy.apply(this,[name,age,sex]);
this.name = name;
this.age = age;
this.sex = sex;
this.teach = function(){
console.log(this.name+"正在讲课");
}
}
module.exports = teacher;
var boy = require("./teacher.js");
var boys = new boy("聂伟博","28","男");
boys.say();
boys.teach();