Node.js中module.exports用法
来源:互联网 发布:通达信短线决策源码 编辑:程序博客网 时间:2024/06/07 07:21
Node.js中module.exports用法
新建两个js文件
//hello.js
function Hello(){ var name; this.setName = function(thyName){ name = thyName; } this.sayHello = function(){ console.log('Hello '+ name); };};module.exports = Hello;
//gethello.js
var Hello = require('./hello');hello = new Hello();hello.setName('Liqiu');hello.sayHello();
在命令行中执行“node gethello.js”命令
另一种创建模块的方法:
//currency.js
var canadianDollar = 0.9;function roundTwoDecimals(amout){ return Math.round(amout * 100)/100;}exports.canadianToUS = function(canadian){ return roundTwoDecimals(canadian * canadianDollar);}exports.USToCanadian = function(us){ return roundTwoDecimals(us / canadianDollar);}
//test-currency.js
var currency = require('./currency');console.log('50 Canadian dollars equals this amount of US dollars');console.log(currency.canadianToUS(50));console.log('30 US dollars equals this amount of Canadian dollars');console.log(currency.USToCanadian(30));
执行结果如下:
0 0
- Node.js中module.exports用法
- Node.js中exports和module.exports
- Node.js中exports与module.exports的区别
- Node.js中module.exports与exports的区别
- node.js中module.exports与exports的区别
- Node.js中exports和module.exports有什么不同?
- 揭秘Node.js中exports和module.exports
- node.js中module.exports和exports的区别
- Node.js Module -moudule.exports vs exports
- Node.js的module.exports与exports
- Node.js中require、exports、module模块的区别
- Node.js Module – exports vs module.exports
- Node.js中exports和module.exports的联系和区别
- Node.js中的模块接口module.exports
- node.js 学习笔记之 module.exports与exports
- Node.js: exports与module.exports的区别
- Node.js模块导出exports 和 module.exports 的区别
- Node.js exports与module.exports的关系
- 每个文件都有 .svn文件的问题
- 后台执行的程序通过system()调用ffmpeg卡住 解决办法
- nyoj 1272 表达式求值(中缀式转后缀式)
- 缓存的基本原理
- jmeter JDBC Configuration && JDBC Request
- Node.js中module.exports用法
- uml九种图之用例图 构建图
- nginx location alias 和 root 差别
- 第5周 项目3 - 括号的匹配(2)
- 二分
- Java中final、finally 和 finalize 的区别
- HDU1008
- C++中的to_string()函数[C++11支持]
- Jar包混淆后引用报错