analogcoding

arrow function 의 this context 본문

Study JS for me/Keyword

arrow function 의 this context

be well 2019. 5. 14. 17:06

일반적인 함수의 경우 this 가 참조하는 값을 binding 해줘야한다.

arrow function 을 사용하지 않을 때 this === window 가 true 이다.

 

this.pruntData() 는 이미 myObj 를 바라보고 있어서 window가 아니기 때문에 bind로 this를 묶어줘야 한다.

 

그렇지만 arrow function을 사용할 경우

binding을 따로 해주지 않아도 바로 연결된다.

그렇지만 this 가 window 를 바라보는 것은 아니다.

 

bind 를 생략한 상태에서도 context 를 유지하기 때문에 'where is this' 가  출력된다.

'Study JS for me > Keyword' 카테고리의 다른 글

function default parameters  (0) 2019.05.14
Destructuring  (0) 2019.05.14
arrow function 예시  (0) 2019.05.14
Object property  (0) 2019.05.13
spread operator / rest parameter  (0) 2019.05.13
Comments