nodejs基础概念解析
2016-07-04 17:13
399 查看
1.什么是回调?
2.什么是同步异步?
3.什么是作用域?
4.this上下文对象
this是指向调用该方法的对象
var learn = function(something) { console.log(something); } var we = function(callback,something){ var something = something + ' is cool'; callback(something); } we(learn,'NodeJs'); we(function(something){ console.log(something); },'Jade')
2.什么是同步异步?
var go_home = function(person){ console.log(person+' go home'); } var wait_classmate = function(person){ setTimeout(function(){ person += 'wait classmate'; go_home(person);//等到同学在回家 },1000); go_home(person);//回家以后等同学 } wait_classmate('xiao ming');
3.什么是作用域?
var globalVariable = "This is a global variable"; var globalFunction = function(){ console.log('visit globalVariable'); console.log(globalVariable); var LocalVariable = "This is a local variable"; var localFunction = function(){ console.log('visit LocalVariable'); console.log(LocalVariable); var innerLocalVariable = "This is a local innerLocalVariable"; var innerLocalFunction = function(){ console.log('visit global/local/innerLocal/Variable'); console.log(globalVariable); console.log(LocalVariable); console.log(innerLocalVariable); } innerLocalFunction(); } localFunction(); } globalFunction();
4.this上下文对象
this是指向调用该方法的对象
var pet = { word:"...", speak:function(){ console.log('speak'+' '+this.word); } } pet.speak();//this指向pet var pet = function(word){ this.word = word; this.speak = function(){ console.log('speak'+' '+this.word); }; } var cat = new pet("Miao"); cat.speak(); cat.word = "Miao Miao MIao ~"; cat.speak(); //指向cat对象 var dog = new pet("wang wang!"); dog.speak(); var petSpeak = function(){ console.log(this==window); } petSpeak();//true var pet = { word:"...", speak:function(){ console.log(this.word); } } pet.speak(); var dog = { word:"wang wang~" } pet.speak.call(dog,'speak');
相关文章推荐
- window下通过nvmw来安装多版本node
- 116. Populating Next Right Pointers in Each Node
- 分布式存储ceph系统性能不稳定因素
- DrawNode
- Nodejs中 npm常用命令详解
- Nodejs全局安装和本地安装的不同之处
- [算法]Java 实现 简单MyNode类型 无序链表 递归 添加 删除 遍历
- 【原】nodejs全局安装和本地安装的区别
- 24. Swap Nodes in Pairs
- bower安装库出现的问题解决办法
- Node.js Streams文件读写操作详解
- 【web】Ubuntu上安装nodejs 4.x 5.x版本方法
- node 关键点总结
- node.js池操作
- 读《nodejs开发指南》记录
- 【腾讯云】配置安装node
- nodejs开发遇到过的坑
- node.js 和 express 框架学习笔记(3)
- nodejs 循环引用JSON序列化错误的解决办法:TypeError: Converting circular structure to JSON
- 基于Node的开发管理工具