nodejs 加载模块

来源:互联网 发布:动态文字特效制作软件 编辑:程序博客网 时间:2024/05/09 18:51
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.a1> a.b2


0 0
原创粉丝点击