-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |