자바스크립트에서 this란 무조건 현재 함수가 호출된 context다
볼래?
console.log(this); // not a function context
function adun () {
console.log(this);
}
adun(); // this is adun Function
function adun2 () {
var a = 2;
console.log(a);
}
adun2(); // 2
자바스크립트에서 this란 무조건 현재 함수가 호출된 context다
볼래?
console.log(this); // not a function context
function adun () {
console.log(this);
}
adun(); // this is adun Function
function adun2 () {
var a = 2;
console.log(a);
}
adun2(); // 2
클라이언트 환경에서 아무런 Context없이 this호출하면 window 나오는 거 맞음?
ㄴ 아닙니다 not a function context 에러가 뜹니다. window가 나오는건 브라우저가 잘못 구현한 버그입니다.
버그 아닙니다 javascript 전역 컨텍스트에선 변수객체 = global(브라우져에선 window) 객체 이기 때문에 당연히 window를 가르킵니다
strict 모드에선 에러가 납니다