質問編集履歴
5
上方修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,12 +32,6 @@
|
|
32
32
|
|
33
33
|
|
34
34
|
|
35
|
-
countdown(3)
|
36
|
-
|
37
|
-
.then((a) => console.log(a))
|
38
|
-
|
39
|
-
.catch((a) => console.error(a));
|
40
|
-
|
41
35
|
```
|
42
36
|
|
43
37
|
|
4
上方修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
```
|
2
|
+
|
1
|
-
|
3
|
+
function countdown(num) {
|
2
4
|
|
3
5
|
return new Promise((onFulfilled, onRejected) => {
|
4
6
|
|
3
上方修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,48 +1,4 @@
|
|
1
|
-
```function addtimeout(fn, period) {
|
2
|
-
|
3
|
-
if (period === undefined) period = 1000;
|
4
|
-
|
5
|
-
return function (...args) {
|
6
|
-
|
7
|
-
return new Promise(function (onFulfilled, onRejected) {
|
8
|
-
|
9
|
-
const timeoutId = setTimeout(
|
10
|
-
|
11
|
-
onRejected,
|
12
|
-
|
13
|
-
period,
|
14
|
-
|
15
|
-
new Error("プロミス タイムアウト")
|
16
|
-
|
17
|
-
);
|
18
|
-
|
19
|
-
fn(...args)
|
20
|
-
|
21
|
-
.then(function (...args) {
|
22
|
-
|
23
|
-
clearTimeout(timeoutId);
|
24
|
-
|
25
|
-
onFulfilled(...args);
|
26
|
-
|
27
|
-
})
|
28
|
-
|
29
|
-
.catch(function (...args) {
|
30
|
-
|
31
|
-
clearTimeout(timeoutId);
|
32
|
-
|
33
|
-
onRejected(...args);
|
34
|
-
|
35
|
-
});
|
36
|
-
|
37
|
-
});
|
38
|
-
|
39
|
-
};
|
40
|
-
|
41
|
-
}
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
function countdown(num) {
|
1
|
+
```function countdown(num) {
|
46
2
|
|
47
3
|
return new Promise((onFulfilled, onRejected) => {
|
48
4
|
|
@@ -72,6 +28,14 @@
|
|
72
28
|
|
73
29
|
.catch((a) => console.error(a));
|
74
30
|
|
31
|
+
|
32
|
+
|
33
|
+
countdown(3)
|
34
|
+
|
35
|
+
.then((a) => console.log(a))
|
36
|
+
|
37
|
+
.catch((a) => console.error(a));
|
38
|
+
|
75
39
|
```
|
76
40
|
|
77
41
|
|
2
上方修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,48 @@
|
|
1
|
+
```function addtimeout(fn, period) {
|
2
|
+
|
3
|
+
if (period === undefined) period = 1000;
|
4
|
+
|
5
|
+
return function (...args) {
|
6
|
+
|
7
|
+
return new Promise(function (onFulfilled, onRejected) {
|
8
|
+
|
9
|
+
const timeoutId = setTimeout(
|
10
|
+
|
11
|
+
onRejected,
|
12
|
+
|
13
|
+
period,
|
14
|
+
|
15
|
+
new Error("プロミス タイムアウト")
|
16
|
+
|
17
|
+
);
|
18
|
+
|
19
|
+
fn(...args)
|
20
|
+
|
21
|
+
.then(function (...args) {
|
22
|
+
|
23
|
+
clearTimeout(timeoutId);
|
24
|
+
|
25
|
+
onFulfilled(...args);
|
26
|
+
|
27
|
+
})
|
28
|
+
|
29
|
+
.catch(function (...args) {
|
30
|
+
|
31
|
+
clearTimeout(timeoutId);
|
32
|
+
|
33
|
+
onRejected(...args);
|
34
|
+
|
35
|
+
});
|
36
|
+
|
37
|
+
});
|
38
|
+
|
39
|
+
};
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
|
1
|
-
|
45
|
+
function countdown(num) {
|
2
46
|
|
3
47
|
return new Promise((onFulfilled, onRejected) => {
|
4
48
|
|
1
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
function countdown(num) {
|
1
|
+
```function countdown(num) {
|
2
2
|
|
3
3
|
return new Promise((onFulfilled, onRejected) => {
|
4
4
|
|
@@ -28,6 +28,8 @@
|
|
28
28
|
|
29
29
|
.catch((a) => console.error(a));
|
30
30
|
|
31
|
+
```
|
32
|
+
|
31
33
|
|
32
34
|
|
33
35
|
これの結果は
|