this의 의미 6개 총정리
this의 의미 6개 총정리
01. this (일반(전역)함수에서 this를 사용하는 경우)
<script>
console.log(this);
function guntion () {
console.log(this);
};
guntion();
</script>// 결과)
window
window02. this (오브젝트 내 함수(메소드)에서 사용하는 경우)
const 오브젝트 = {
data: 'SO',
methods : function(){
naming : function() {
console.log(this); //여기서의 this는 naming를 가지고 있는 methods를 뜻함
}
}
}
오브젝트.함수();03. this (arrow function에서 사용하는 경우)
04. this (01번과 02번은 같은 이야기인 이유(window의 비밀) )
05. this (constructor(생성자)에서 this 사용하는 경우)
06. this (event listener 내에서 사용하는 경우)
Last updated