nodejs模块

module.exports=function(){  //新建模块,自定义方法
var name="";
var a=12;
this.setName=function(theName){  //设置名字
name=theName;
}
this.sayHello=function(){  //输出
console.log("hello"+name);
}
this.cona=function(){  //输出
console.log(a);
}
}

 

//引入模块

var mod = require('./mod'); 

var   mod1 = new mod();  //实例化
mod1.setName("q");//设置名称
mod1.sayHello();//输出
mod1.cona();

 

//输出

helloq

12 

 

posted @ 2019-05-07 10:01  Sun_Song  阅读(109)  评论(0编辑  收藏  举报