Tags
- solidity
- postman pre-request
- Java
- postman html parse
- C++
- oracle
- postman session
- Interaction developer
- Front-end developer
- emplace_back
- Intellij
- 우수한 프런트 개발자
- postman tests
- Android
- postman automations
- c#
- UI/UX Engineer
- web developer
- postman
- postman csv
- LSL_Script
- MFC
- 다빈치 리졸브
- Android/iOS Developer
- 좋은 개발자
- 프런트엔드
- postman collection
- postman excel
- Unity
- postman collection variables
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Archives
- Today
- Total
david's daily developer note
[FE] JavaScript에서 함수는 일급 (first class citizen)이다. 본문
[Develop] Web/Front-end
[FE] JavaScript에서 함수는 일급 (first class citizen)이다.
mouse-david 2022. 6. 17. 01:15728x90
JavaScript에서 함수는 일급 (first class citizen)이다.
다음은 js에서 함수가 일급인 이유이며, js가 함수형 프로그래밍에 유리하고 인기가 많은 이유이다.
#일급
- 값으로 다룰 수 있다.
- 변수에 담을 수 있다.
- 함수의 인자로 사용될 수 있다.
- 함수의 결과로 사용될 수 있다.
다음은 "함수를 값으로 다룰 수 있다"의 예시이다.
"a => a + 1" 함수를 값 처럼 다루면서 sum1 변수에 담고 사용하는 예제이다.
<script>
const a = 10;
const sum1 = a => a + 1;
const r = sum1(a);
<script>
함수를 값으로 다루는 함수를 고차 함수(Higher-order function)라고 한다.
다음 ffunc 함수는 함수를 인자로 받고 수행될 수 있다.
<script>
const ffunc = f => f(1);
const sum1 = a => a + 1;
console.log (ffunc(sum1));
console.log (ffunc(a => a * a));
</script>
함수를 반환하는 고차 함수의 경우에는 클로저(Closure)를 만들어서 반환한다.
<script>
const sumCreator = a => b => a + b;
const sum1 = sumCreator(1);
console.log(sum1(5));
console.log(sum1(10));
</script>
728x90
'[Develop] Web > Front-end' 카테고리의 다른 글
[FE] 크롬 개발자 도구, 팝업 페이지에서 자동 실행 설정(Chrome DevTools Auto-open for popups) (0) | 2022.06.27 |
---|---|
[FE] JavaScript Iterator and iterable protocols (0) | 2022.06.19 |
[FE] vs code에서 TypeScript 컴파일 설정하기 (0) | 2022.06.15 |