Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Github
- java.sql.SQLException: Incorrect string value: #RDS #AWS #mariadb #springboot
- Disk추가
- 명령어 모음
- VSCode업로드
- Spring
- 공동작업자
- react-dom
- 편집모드
- html템플릿
- GiyHub
- Push
- linux Xshell
- javascript
- aws
- SpringBoot개발환경
- oracle vm virtualbox
- Biling and Cost Manager
- 사용자 권한 부여
- 코딩애플
- OracleVMVirtualBox
- 구성파일
- AWS #AWS장단점 #AWS차별화 # AWS서비스
- react
- VSCode
- 코테관련공부
- insert안됨
- EaaS
- Linux
- Function
Archives
- Today
- Total
귀농 전까지 쓰는 개발 일지
[JavaScript] function(2) - 활용, Arrow Function 본문
(1) First-class Function
//1, 함수를 변수처럼 처리
const func = function(...args) {
console.log('print func');
for(const arg of args )console.log(arg); //매개변수 인자가 넘어오면 모두 출력
};
//2, 변수에 값으로 할당
const show = func;
show('인자','전달'); // print func, 인자, 전달 출력
func(); // print func 출력

//3, 함수를 다른 함수의 인자(argument)로 사용하여 Callback 처리
function quiz(answer, Yes, No){
if(answer === 'Home'){
Yes(); //console.log('yes func print') 실행하는 함수
} else {
No(); //console.log('no func print') 실행하는 함수
}
}
const printYes = function(){
console.log('yes func print');
}
const printNo = function(){
console.log('no func print');
}
//printYes, printNo 함수를 quiz 함수의 인자 값으로 사용함
quiz('Home', printYes, printNo); //yes func print 출력됨
quiz('no Home', printYes, printNo); // no func print 출력됨
//4, 다른 함수를 함수의 반환 값으로 사용 가능
function outer(){
return function inner(){ 'inner함수 반환값으로 사용' }
}
console.log( outer() ); // f inner(){ 'inner함수 반환값으로 사용' } 출력됨

(2) Arrow Function (=> 함수) 기본 형태
//1. 기본 표현법
const arrowEx = function() {
console.log('Basic Function Example');
}
//=> 변경
const arrowEx = () =>
console.log('arrow Function One');
//=> 변경 대괄호 사용
const arrowEx = () => {
console.log('arrow Function Two');
}
(2)-1 Arrow Function (=> 함수) 파라미터 전달
<script>
// 파라미터가 1개인 경우
const paramOne = a =>
console.log(a);
paramOne('파라미터 1개 전달');
// 파라미터 2개 전달
const paramTwo = (a, b) =>
console.log( a+b );
paramTwo(5,10);
</script>
*함수 내의 코드가 한줄이면 return 생략*
'공부 > JavaScript' 카테고리의 다른 글
[JavaScript] 배열 (0) | 2022.01.17 |
---|---|
[JavaScript] 자료형 (0) | 2022.01.17 |
[JavaScript] function(3) - IIFE / Closure (0) | 2022.01.17 |
[JavaScript] function(1)-형태/기본값/가변인자 (0) | 2022.01.17 |
[JavaScript] 개요_출력 (0) | 2022.01.17 |