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