node模块引入

定义a.js为变量模块:

var seel="南阳";
exports.seel=seel;     //使用exports将变量seel向外暴露

定义b.js为对象模块:

function people(name,age,sex){
	this.name=name;
	this.age=age;
	this.sex=sex;
}
people.prototype={
	say:function(){
		console.log(this.name+this.age+this.sex);
	}
}
module.exports=people;   //使用module.exports将people对象向外暴露,引用模块就可以新建people类对象

在模块c.js中引用两个模块:

var people=require("./b.js");
var ne=require("./a.js");
var xiaoming=new people("小明",23,"男");
xiaoming.say();
console.log(ne.seel);

你可能感兴趣的:(Node)