質問編集履歴
5
上方修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -15,9 +15,6 @@
|
|
15
15
|
.then((a) => console.log(a))
|
16
16
|
.catch((a) => console.error(a));
|
17
17
|
|
18
|
-
countdown(3)
|
19
|
-
.then((a) => console.log(a))
|
20
|
-
.catch((a) => console.error(a));
|
21
18
|
```
|
22
19
|
|
23
20
|
これの結果は
|
4
上方修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
+
```
|
1
|
-
|
2
|
+
function countdown(num) {
|
2
3
|
return new Promise((onFulfilled, onRejected) => {
|
3
4
|
for (let i = num; i >= -1; i--) {
|
4
5
|
setTimeout((i) => {
|
3
上方修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,26 +1,4 @@
|
|
1
|
-
```function addtimeout(fn, period) {
|
2
|
-
if (period === undefined) period = 1000;
|
3
|
-
return function (...args) {
|
4
|
-
return new Promise(function (onFulfilled, onRejected) {
|
5
|
-
const timeoutId = setTimeout(
|
6
|
-
onRejected,
|
7
|
-
period,
|
8
|
-
new Error("プロミス タイムアウト")
|
9
|
-
);
|
10
|
-
fn(...args)
|
11
|
-
.then(function (...args) {
|
12
|
-
clearTimeout(timeoutId);
|
13
|
-
onFulfilled(...args);
|
14
|
-
})
|
15
|
-
.catch(function (...args) {
|
16
|
-
clearTimeout(timeoutId);
|
17
|
-
onRejected(...args);
|
18
|
-
});
|
19
|
-
});
|
20
|
-
};
|
21
|
-
}
|
22
|
-
|
23
|
-
function countdown(num) {
|
1
|
+
```function countdown(num) {
|
24
2
|
return new Promise((onFulfilled, onRejected) => {
|
25
3
|
for (let i = num; i >= -1; i--) {
|
26
4
|
setTimeout((i) => {
|
@@ -35,6 +13,10 @@
|
|
35
13
|
countdown(3)
|
36
14
|
.then((a) => console.log(a))
|
37
15
|
.catch((a) => console.error(a));
|
16
|
+
|
17
|
+
countdown(3)
|
18
|
+
.then((a) => console.log(a))
|
19
|
+
.catch((a) => console.error(a));
|
38
20
|
```
|
39
21
|
|
40
22
|
これの結果は
|
2
上方修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,26 @@
|
|
1
|
+
```function addtimeout(fn, period) {
|
2
|
+
if (period === undefined) period = 1000;
|
3
|
+
return function (...args) {
|
4
|
+
return new Promise(function (onFulfilled, onRejected) {
|
5
|
+
const timeoutId = setTimeout(
|
6
|
+
onRejected,
|
7
|
+
period,
|
8
|
+
new Error("プロミス タイムアウト")
|
9
|
+
);
|
10
|
+
fn(...args)
|
11
|
+
.then(function (...args) {
|
12
|
+
clearTimeout(timeoutId);
|
13
|
+
onFulfilled(...args);
|
14
|
+
})
|
15
|
+
.catch(function (...args) {
|
16
|
+
clearTimeout(timeoutId);
|
17
|
+
onRejected(...args);
|
18
|
+
});
|
19
|
+
});
|
20
|
+
};
|
21
|
+
}
|
22
|
+
|
1
|
-
|
23
|
+
function countdown(num) {
|
2
24
|
return new Promise((onFulfilled, onRejected) => {
|
3
25
|
for (let i = num; i >= -1; i--) {
|
4
26
|
setTimeout((i) => {
|
1
書式の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
function countdown(num) {
|
1
|
+
```function countdown(num) {
|
2
2
|
return new Promise((onFulfilled, onRejected) => {
|
3
3
|
for (let i = num; i >= -1; i--) {
|
4
4
|
setTimeout((i) => {
|
@@ -13,6 +13,7 @@
|
|
13
13
|
countdown(3)
|
14
14
|
.then((a) => console.log(a))
|
15
15
|
.catch((a) => console.error(a));
|
16
|
+
```
|
16
17
|
|
17
18
|
これの結果は
|
18
19
|
3
|