-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14.js_callback.html
More file actions
40 lines (36 loc) · 1.26 KB
/
Copy path14.js_callback.html
File metadata and controls
40 lines (36 loc) · 1.26 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>js 콜백함수</title>
</head>
<body>
<button onclick="basicFunthion()">일반함수 예제</button>
<button onclick="callbackFunction1()">콜백함수 예제1</button>
<button onclick="callbackFunction2()">콜백함수 예제2(동기적실행)</button>
<button onclick="callbackFunction3()">콜백함수 예제3(비동기실행)</button>
<script>
function basicFunthion() {
alert('hello world');
}
function callbackFunction1() {
userInput((a)=>{console.log(a)});
}
function userInput(callback) {
callback("hongildong");
}
function callbackFunction2() {
const numbers = [1,2,3,4,5];
numbers.forEach((a)=>console.log(a));
console.log('hello world');
}
function callbackFunction3() {
// setTimeout 함수는 js의 대표적인 비동기함수 중 하나(+콜백함수처리)
setTimeout(()=>console.log('hello world1'), 2000);
console.log('hello world2');
console.log('hello world3');
}
</script>
</body>
</html>