-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
113 lines (102 loc) · 2.97 KB
/
index.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html>
<head>
<title>测试</title>
<script type="text/javascript" src="./dist/promise.js"></script>
</head>
<body>
<script type="text/javascript">
// new Promise(1).then(function(a){console.log(a)});
// var p = new Promise(function(resolve,reject){reject(5)});
// // console.log(p);
// p.then(function(a){
// console.log(a)
// },function(a){
// console.log('reject' + a)
// } )
// var p = Promise.resolve(5);
// new Promise(function(resolve,reject){resolve(p)}).then(function(a){console.log('fulfill'+a)},function(a){console.log('reject'+a)})
// var a = new Promise(function(resolve){setTimeout(()=>{resolve(55)},3000)}).then(function(a){console.log(a);return 10;}).then(function(b){console.log('2222',b)})
function defer(){
var dfd = {}
dfd.promise = new Promise1(function(resolve, reject) {
dfd.resolve = resolve
dfd.reject = reject
})
return dfd
}
// var d = defer();
// (function(){
// d.promise.then(function onFulfilled(a) {
// console.log(a);
// }, function onRejected() {
// console.log(false);
// });
// setTimeout(()=>{console.log('haha')},100)
// })()
// d.resolve({ dummy: "dummy" });
// var d = defer();
// var isFulfilled = false;
// d.promise.then(function onFulfilled() {
// console.log(isFulfilled)
// });
// setTimeout(function () {
// d.resolve({ dummy: "dummy" });
// isFulfilled = true;
// }, 50);
// var promise = Promise1.reject({ dummy: "dummy" }).then(null, function () {
// return promise;
// });
// promise.then(null, function (reason) {
// console.log(reason);
// });
// function callbackAggregator(times, ultimateCallback) {
// var soFar = 0;
// return function () {
// console.log(soFar);
// if (++soFar === times) {
// ultimateCallback();
// }
// };
// }
// var semiDone = callbackAggregator(3, function(){console.log('gagsgs');});
// var promise = Promise1.resolve({ dummy: "dummy" });
// promise.then(function () {
// return { sentinel: "sentinel" };
// }).then(function (value) {
// console.log(value);
// semiDone();
// });
// promise.then(function () {
// throw { sentinel2: "sentinel2" };
// }).then(null, function (reason) {
// console.log(reason)
// semiDone();
// });
// promise.then(function () {
// return { sentinel3: "sentinel3" };
// }).then(function (value) {
// console.log('sentinel3');
// semiDone();
// });
var promise = Promise1.resolve({ dummy: "dummy" }).then(()=>{
return defer().promise;
})
console.log(promise);
var wasFulfilled = false;
var wasRejected = false;
promise.then(
function onPromiseFulfilled() {
wasFulfilled = true;
},
function onPromiseRejected() {
wasRejected = true;
}
);
setTimeout(function () {
console.log(wasFulfilled);
console.log(wasRejected);
}, 100);
</script>
</body>
</html>