[JS] ES6 - Functions
이채현
Functions
Arrow Functions
기존 함수의 모습을 개선했다.
기존 함수
1 | function Hello() { |
Arrow Functions(1) - base
1 | const Hello = () => { |
Arrow Functions(2) - implicit return
1 | const Hello = () => "hi"; |
this
in Arrow Functions (Event listener in arrow function)
일반 콜백 함수안에서 this
는 이벤트리스너에 연결 된 엘리먼트를 가리킨다. 하지만, arrow function안에서 this
는 window를 가리킨다.
결론, this를 함수 안에 익명함수로 사용할 때는 Arrow Function이 아닌 일반 표준 funtion 형태로 사용해야한다.
1 | const thisTest = { |
Default Values
1 | const sayHi = (aName = "anon") => { |
[JS] ES6 - Functions
https://devch.co.kr/categories/웹앱/Javascript/JS-ES6-2-22-01-01/