-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7. 비동기.html
52 lines (46 loc) · 1.16 KB
/
7. 비동기.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>7. 비동기</title>
<script src="js/partial.js"></script>
<script src="js/_.js"></script>
</head>
<body>
<script>
function square(a) {
return new Promise(function (resolve) {
setTimeout(function () {
resolve(a*a)
}, 500)
})
};
square(10)
.then(square)
.then(square)
.then(square)
.then(console.log);
_.go(square(10),
square,
square,
square,
console.log
);
var list = [2, 3, 4];
new Promise(function(resolve) {
(function recur(res) {
if (list.length == res.length) return resolve(res);
square(list[res.length]).then(function(val) {
res.push(val);
recur(res);
});
})([]);
}).then(console.log);
_.go(list,
_.map(square),
_.map(square),
_.map(square),
console.log);
</script>
</body>
</html>