- 그럼 람다가 뭔데..
람다 vs 평소 쓰던방식
- 매개변수가 1개 일 경우 ( )생략가능 or 코드가 1줄일 경우 { }를 생략 할 수 있다
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button id="btn" onclick="f2()">run1</button>
<hr>
<p id="demo"></p>
<script>
const btn = document.querySelector("#btn");
btn.addEventListener("click", f);
function f() {
fetch('https://jsonplaceholder.typicode.com/users')
.then(resp => resp.text())
.then(value1 => document.getElementById("demo").innerHTML = value1)
}
function f2() {
fetch('https://jsonplaceholder.typicode.com/users')
.then(resp => {
return resp.text()
})
.then(function(value1) {
document.getElementById("demo").innerHTML = value1;
})
}
let f3 = function(a,b) {
let c = a+b;
return c;
}
let f4 = (a,b) =>{
let c = a+b;
return c;
}
let f5 = (a,b) => a+b;
</script>
</body>
</html>
'JSP > 이론' 카테고리의 다른 글
fetch post방식 (0) | 2023.07.14 |
---|---|
콜백함수?//fetch (ajax 새로운 함수) //람다식 (0) | 2023.07.14 |
카카오 map api (0) | 2023.07.06 |
JUnit(단위테스트 도구)//assertEquals (0) | 2023.07.04 |
form으로 데이터 빈공백으로 보내면 null체크여부 (0) | 2023.07.03 |