Skip to content

Commit

Permalink
node class add http module
Browse files Browse the repository at this point in the history
  • Loading branch information
kugouming committed Jan 18, 2016
1 parent 87728e4 commit d585ae8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
39 changes: 39 additions & 0 deletions class-http/async.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var c = 0

function printIt() {
console.log(c)
}

// step 1:
// 同步执行
/*
function plus() {
c += 1
}
*/

// step 2:
// 同步执行收到干扰
/*
function plus() {
setTimeout(function(){
c += 1;
},1000);
}
*/

// step 3:
// Callback 方式实现同步执行 => 异步编程实现非堵塞
function plus(callback) {
setTimeout(function() {
c += 1;
callback();
},1000);
}

// step 1 & 2 :
//plus()
//printIt()

// step 3:
plus(printIt)
15 changes: 15 additions & 0 deletions class-http/callback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function learn(something) {
console.log(something)
}

function we(callback, something) {
something += ' is so cool'
callback(something)
}

we(learn, 'Node')

// 匿名函数
we(function(something){
console.log('The second : ' + something)
}, 'Jade')
7 changes: 7 additions & 0 deletions class-http/event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function clickIt() {
window.alert('Button is clicked')
}

var button = document.getElementById('#button')

button.addEventListener('click', clickIt)

0 comments on commit d585ae8

Please sign in to comment.