JavaScript - Arrow Function, Rest Parameter

LANA·2020년 4월 30일
0

JavaScript

목록 보기
16/21

그냥 강의 들으면서 혼자 정리한 것... 다시 듣고 추가해야함


Arrow Function

Arrow function은 block scope

let은 hoist가 안됨
let은 중복해서 뭔가를 선언하려고 할 때 syntax error가 남
const는 같은 경우에서 type error가 남. constant라서?


()로 묶어주면 표현식으로 여겨져서 interpreter가 실행시킴
but 모양새가 안예쁨

.
.
.


차라리 이렇게 쓰는게 나음

Arrow function 안쓰는 경우

  • new키워드가 필요할 때
    • 전통적인 function을 쓰거나
    • class keyword를 써야함.
    • 왜? arrow는 constructor(생성자)가 아님. Construction mode를 아예 할 수가 없음

Arrow function 쓰는 경우

  • lexical한 this를 가지고 싶을때(arrow는 lexical한 this를 가짐)
  • 독자적인 execution context를 만들고 싶지 않을 때

Rest Parameter


rest parameter를 쓴 args는 배열임을 잊지 말자

참고
1. 비구조화 할당에 대해서도 알아보기
2. this 다시..!

profile
Let's code like chord !

0개의 댓글