자바스크립트 함수 내부에서의 this
는 일반 함수와 화살표 함수에서서 this가 다르다.
일반(Normal) 함수는 호출 위치에 따라 this를 정의하고 화살표(Arrow) 함수는 자신이 선언된 함수 범위에서 this를 정의한다.
const mooooburg = {
name: 'mooooburg',
normal: function() {
console.log(this.name)
}
arrow: () => {
console.log(this.name)
}
}
mooooburg.normal() // mooooburg
mooooburg.arrow() // undefined
const amy = {
name: 'Amy',
normal: mooooburg.normal,
arror: mooooburg.arrow
}
amy.normal() // mooooburg
amy.arrow() // undefined