function hello(){
var name;
this.setName = function(n){
name = n;
}
this.sayHello = function(){
console.log('Hello ' + name);
}
}
module.exports = hello;
加载的是类型
var hello = require('./hello');
var h = new hello();
h.setName('xiuye');
h.sayHello();
var a = {a:1,b:2,c:3};
module.exports = a;
加载的是对象实例
xiuye@ubuntu:~/workspace$ nodejs
> require("./test");
{ a: 1, b: 2, c: 3 }
> a = require("./test");
{ a: 1, b: 2, c: 3 }
> a
{ a: 1, b: 2, c: 3 }
> a.a
1
> a.b
2