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.
26. ES6 함수의 추가 기능
✏️ 기억에 남는 내용
ES6에서는 함수를 사용 목적에 따라 다음과 같은 세 가지 종류로 명확히 구분했다.
ES6 이전 사양에는 메서드에 대한 명확한 정의가 없었다. ES6 사양에서 메서드는 메서드 축약 표현으로 정의된 함수만을 의미한다.
화살표 함수와 일반 함수의 차이
화살표 함수의 this는 일반 함수의 this와 다르게 동작한다. 이를 통해 "콜백 함수 내부의 this 문제", 즉 콜백 함수 내부의 this가 외부 함수의 this와 다르기 때문에 발생하는 문제를 해결할 수 있다.
화살표 함수 내부에서 super를 참조하면 this와 마찬가지로 상위 스코프의 super를 참조한다.
화살표 함수 내부에서 arguments를 참조하면 this와 마찬가지로 상위 스코프의 arguments를 참조한다.
Rest 파라미터는 함수에 전달된 인수들의 목록을 배열로 전달받는다.
arguments 객체는 배열이 아닌 유사 배열 객체이므로 배열 메서드를 사용하려면 Function.prototype.call 이나 Function.prototype.apply 메서드를 사용해 arguments 객체를 배열로 변환해야 한다.
📝 간단한 퀴즈
자바스크립트의 함수는 다양한 형태로 호출할 수 있다. 자바스크립트의 함수 호출 방법을 모두 작성하고 어느 시점에 어떤 호출 방법을 사용해야 할지 간단하게 이야기해보자.
화살표 함수와 일반 함수의 차이를 간단하게 작성해보자.
"콜백 함수 내부의 this문제"가 무엇인지 간단하게 작성하고 그 해결 방법을 화살표 함수와 연관지어 작성해보자. (화살표 함수가 없던 ES6 이전에는 이 문제를 어떻게 해결했을까?)
🧑🏻💻 연관 코드