forked from RubyLouvre/mmDeferred
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.html
56 lines (49 loc) · 1.75 KB
/
notify.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="deferred.js"></script>
<script>
window.onload = function() {
var oldConsole = window.console
window.console = {
log: function(str) {
if (oldConsole) {
oldConsole.log(str)
}
var div = document.createElement("div")
div.innerHTML = window.JSON ? JSON.stringify(str) : str;
document.body.appendChild(div);
}
}
function startNotify() {
var dfd = Deferred(), count = 0;
var intervalId = setInterval(function() {
dfd.notify(count++);
count > 10 && clearInterval(intervalId);
}, 500);
return dfd.promise;
}
startNotify().then(function(a) {
console.log(a + " resolve 0");
return 10
}, function(a) {
console.log(a + " reject 0")
}, function(a) {
console.log(a + " notify 0")
return "N"
}).then(function(a) {
console.log(a + " resolve 1");
}, function(a) {
console.log(a + " reject 1")
}, function(a) {
console.log(a + " notify 1")
})
}
</script>
</head>
<body>
<div>TEST by 司徒正美</div>
</body>
</html>