回答編集履歴
2
ちょっと修正
test
CHANGED
@@ -20,11 +20,15 @@
|
|
20
20
|
|
21
21
|
new Promise(function(resolver){
|
22
22
|
|
23
|
-
setTimeout(function(){
|
23
|
+
setTimeout(function(){
|
24
|
+
|
25
|
+
console.log(x);
|
26
|
+
|
27
|
+
return resolver(this);
|
28
|
+
|
29
|
+
},1000);
|
24
30
|
|
25
31
|
}).then(function(){
|
26
|
-
|
27
|
-
console.log(x);
|
28
32
|
|
29
33
|
if(x<prm.length){
|
30
34
|
|
1
sample
test
CHANGED
@@ -1 +1,51 @@
|
|
1
1
|
Promiseで処理するとかでしょうか?
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
# sample
|
6
|
+
|
7
|
+
一応非同期処理を、順番を指定して実行するsampleを付けておきます
|
8
|
+
|
9
|
+
```javascript
|
10
|
+
|
11
|
+
<script src="https://www.promisejs.org/polyfills/promise-6.1.0.min.js"></script>
|
12
|
+
|
13
|
+
<script>
|
14
|
+
|
15
|
+
var prm=[];
|
16
|
+
|
17
|
+
for(var i=0;i<10;i++){
|
18
|
+
|
19
|
+
prm[i]=function(x){
|
20
|
+
|
21
|
+
new Promise(function(resolver){
|
22
|
+
|
23
|
+
setTimeout(function(){return resolver(this)},1000);
|
24
|
+
|
25
|
+
}).then(function(){
|
26
|
+
|
27
|
+
console.log(x);
|
28
|
+
|
29
|
+
if(x<prm.length){
|
30
|
+
|
31
|
+
prm[x](x+1);
|
32
|
+
|
33
|
+
}else{
|
34
|
+
|
35
|
+
console.log("end");
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
});
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
prm[0](1);//実行
|
46
|
+
|
47
|
+
</script>
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
```
|