原创转载请注明出处:http://agilestyle.iteye.com/blog/2354063
Project Directory
exports.xxx = function() {}
hello.js
exports.world = function() { console.log("Hello World"); };
module.exports = xxx
world.js
function Person(name) { this.name = name; } Person.prototype = { constructor: Person, sayName: function() { console.log(this.name); }, toString: function() { return "[Person " + this.name + "]"; } }; module.exports = Person;
index.js
// exports.world var hello = require('./hello'); hello.world(); // module.exports var world = require('./world'); person = new world(); person.sayName(); person = new world('nodejs'); person.sayName();
Run
Conclusion
外部引用exports.xxx = function() {}和module.exports = xxx模块接口的唯一区别就是后者需要new一下。
Reference
更加详细的解释可以参考
相关推荐
nodejs win7 64 编译好的canvas module
nodejs的express部署包。 如果用npm install下载不到的话(通常是由于代理问题), 那么可以把包中的内容直接解压到node_modules下即可。 相当于手动安装
trymodule - 一个简单的cli工具来尝试不同nodejs模块
nodejs初级教程
CENSOR NODEJS MODULE
NodeJs - Native实现短信验证码注册登录完整示例:NodeJs - Native.js和附件说明
NodeJS
Node.js MQTT客户端的Milkcocoa快速示例。 npm install mqtt node index.js
nodejs-microservice-starter, NodeJS RESTful API Microservice Starter NodeJS RESTful API Microservice v1.2.0这个存储库包含运行 NodeJS rest式 API Microservice启动器的完整配置。 要求NodeJS用于本地开
节点js NodeJS示例项目
,nodEjs ,nodEjs ,nodEjs ,nodEjs ,nodEjs ,nodEjs ,nodEjs ,nodEjs ,nodEjs
nodejs安装及环境配置
资源名称:NodeJs技术经典文档资源目录:【】Node.js开发指南_中文正版【】nodejs开发指南pdf及源码及win安装程序【】nodejs手册中文【】NodeJs教程【】umav4simple【】七天学会NodeJS【】七天学会NodeJS【】深入浅...
nodejs短信接口开发_nodejs发送短信验证码通知_nodejs短信demo示例.docx
NodeJS开发指南
nodejs 学习笔记 nodejs 学习笔记 nodejs 学习笔记
nodejs云计算相关资料
nodejs-module-require 是一个自定义模块加载器 返回一个 {function},它正在加载类并将它们存储在一个对象中,还提供了一些额外的功能 如何使用: var mrequire = require ( "module-require" ) ; 加载快递库 ...
liunx nodejs+nginx配置收藏版liunx nodejs+nginx配置收藏版