回答編集履歴
1
sample
test
CHANGED
@@ -1 +1,55 @@
|
|
1
1
|
単純に言えば(主に並行稼動する)非同期処理を待つ処理
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
# sample
|
6
|
+
|
7
|
+
sampleつけときます
|
8
|
+
|
9
|
+
(IE対応のためpromisejsを読み込んでください、IE無視してよいなら不要です)
|
10
|
+
|
11
|
+
```javascript
|
12
|
+
|
13
|
+
<script src="https://www.promisejs.org/polyfills/promise-6.1.0.min.js"></script>
|
14
|
+
|
15
|
+
<script>
|
16
|
+
|
17
|
+
var a=0;
|
18
|
+
|
19
|
+
var prm=[];
|
20
|
+
|
21
|
+
function test(){
|
22
|
+
|
23
|
+
prm[0]= new Promise(function(resolver){
|
24
|
+
|
25
|
+
setTimeout(function(){a+=1;console.log(a);resolver(this);},1000);
|
26
|
+
|
27
|
+
});
|
28
|
+
|
29
|
+
prm[1]= new Promise(function(resolver){
|
30
|
+
|
31
|
+
setTimeout(function(){a+=10;console.log(a);resolver(this);},2000);
|
32
|
+
|
33
|
+
});
|
34
|
+
|
35
|
+
prm[2]= new Promise(function(resolver){
|
36
|
+
|
37
|
+
setTimeout(function(){a+=100;console.log(a);resolver(this);},3000);
|
38
|
+
|
39
|
+
});
|
40
|
+
|
41
|
+
Promise.all( prm ).then(function(){
|
42
|
+
|
43
|
+
console.log("end");
|
44
|
+
|
45
|
+
});
|
46
|
+
|
47
|
+
};
|
48
|
+
|
49
|
+
test();
|
50
|
+
|
51
|
+
</script>
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
```
|