nodejs 加载模块
2016-03-25 19:47
465 查看
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
相关文章推荐
- nodejs event(有点观察者模式)
- iOS xml文件的解析方式 XMLDictionary,GDataXMLNode,NSXMLParser
- Hadoop格式化namenode失败
- nodejs
- nodejs之express 模块 配置多个静态访问目录
- Leetcode OJ -Remove Nth Node From End of List
- leetcode-24 Swap Nodes in Pairs
- leetcode-19 Remove Nth Node From End of List
- 进程与线程。js是什么运行机制?node.js是什么运行机制?
- DataNode启动失败解决
- Namenode HA
- nodejs nodejs模块使用及简单的示例
- 初学node.js
- 初学nodejs
- leetcode 25. Reverse Nodes in k-Group
- leetcode 24. Swap Nodes in Pairs
- nodejs笔记三--url处理、Query String;
- nodejs笔记二--文件I/O;
- leetcode @python 117. Populating Next Right Pointers in Each Node II.py
- nodejs笔记一--模块,全局process对象;