화살표 함수와 this 캡처

화살표 함수는 짧게 쓰는 함수 문법이 아니라 자신만의 this를 만들지 않고 바깥 lexical scope의 this를 그대로 쓴다.

상황결과좋은 패턴위험 패턴
Class callback인스턴스 this 유지field arrow handler불필요한 bind 반복
Array callbackthis보다 값 변환이 핵심map/filter arrow복잡한 side effect 숨김
Object literal객체가 this가 되지 않음일반 method syntax 사용arrow method로 this undefined
DOM listener바깥 this 유지event.currentTarget 사용this가 DOM일 거라 기대
Nested function바깥 문맥 보존짧은 내부 콜백어느 this인지 추적 불가

화살표 함수의 장점은 this를 고정하는 것이 아니라 바깥 문맥을 그대로 따라가게 하는 데 있다.