Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
주제: 콜백함수, 화살표함수, Object.assign()
1. 콜백 함수
콜백 함수란? 매개변수로 함수 객체를 전달해서 호출 함수 내에서 매개변수 함수를 실행하는 것
비동기 프로그래밍을 할 때 많이 사용함
장점:
ㄴ 콜백 지옥: 콜백 함수를 연속해서 쓸 때 코드의 들여쓰기 수준이 과도하게 깊어지는 것, 가독성 안 좋음
예시 코드 출력 결과:
2초 후 작업 시작...
(2초 후)
작업 완료!
후처리 실행
2. 화살표 함수
화살표 함수란? function 키워드 대신 =>를 사용하는 함수 표현식
장점: 콜백 함수나 간단한 계산을 할 때 유용함
단점: this, arguments, super가 없고, 생성자 함수로 사용 불가
화살표 함수 활용 예시
예시 코드 출력 결과:
5
3. Object.assign(target, sources) 함수
Object.assign 함수란? 하나 이상의 source 객체를 target 객체에 복사해서 합치는 것
target에는 복사한 내용을 담을 대상 객체
sources에는 복사해올 원본 객체들 (여러 개)
장점:
단점: 얕은 복사만 가능
활용 예시
예시 코드 출력 결과:
{ name: "은별", age: 20 }
false