Nodejs_day04
Nodejs模块系统
1.如何创建一个模块
创建一个js(hello.js)
exports.world = function(){//为什么可以这么写,因为exports是nodejs公开的借口
console.log('hello nodejs');
}
使用:
var hello = require('./hello')
hello.world();//打印结果:hello nodejs
有时候我们只想把一个对象封装到模块中,我们可以这么操作
function Hello(){
var name ;
this.setName = function(thyname){
name = thyname;
}
this.sayHello = function(){
console.log('hello '+name);
}
}
module.exports = Hello;
使用
var Hello = require('./hello');//默认后缀名就是.js
var hello = new Hello();
hello.setName('liyajie');
hello.sayHello();
//结果打印:hello liyajie
Nodejs_day04的更多相关文章
随机推荐
- Myeclipse 10 破解说明
一,准备阶段 : 1. 破解软件(网上有下载) 2. JDK软件(免费软件) 二,开始破解: 1. 关闭MyEclipse 10.0 2. 安装 JDK 三,特殊说明: 有些机器安装时会出现run.b ...
- docker 笔记(基本概念、快速运行、自定义镜像)
1.docker docker是一个打包应用的工具 非常强大,能把操作系统也打在包里,进行无差别部署和运行. 所以docker也被认为是建立在操作系统上的虚拟机. 2.基本概念 镜像(image) ...
- 更改win7资源管理器启动位置
打开资源管理器属性,在目标(T)后边加上: /e,::{20D04FE0-3AEA-1069-A2D8-08002B30309D} 俺滴笨笨原本目标(T)是: %windir%\explorer.ex ...
- 解决docker中DNS查询的问题
I got a dns error that i can not access dns server, that caused by : /etc/resolv.conf you can find t ...
- AOJ 0525 - Osenbei
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=50785 翻译:http://blog.csdn.net/acm_10000h ...
- linux环境变量(转)
转自: http://www.cnblogs.com/growup/archive/2011/07/02/2096142.html Linux 的变量可分为两类:环境变量和本地变量 环境变量 或者称为 ...
- 在C#中dagagridview绑定list泛型
今天在项目中由于需要使用到datagridview绑定list的数据源,在针对list的添加.删除.修改都可以很好地完成,可是在初始化datagridview时,却发现了问题,绑定数据源后,并没有在列 ...
- Restrict each user to a single session in window server 2008 R2 or 2012
Restrict each user to a single session in window server 2008 R2 or 2012 2014-10-31 In window server ...
- depth_write
Sets whether or not this pass renders with depth-buffer writing on or not. Format: depth_write <o ...
- 为Gradle添加tomcat插件,调试WEB应用
Gradle提供了不输于maven的依赖管理 提供了强大的test功能,输出优美的测试报告 并且提供war插件,使用内置的jetty调试WEB应用 因为博主偏偏钟情于tomcat,所以希望使用tomc ...