일반 함수 실행 방식
Regular function call - 일반 함수 실행 방식
1-1. non-strict mode (스트릭트 모드가 아닌 일반 모드)
this
의 값은 글로벌 객체, 즉 윈도우 객체입니다.
function foo () {
console.log(this); // 'this' === global object (브라우저상에선 window 객체)
}
foo();
1-2: strict mode
this
의 값은 undefined
입니다.
'use strict';
var name = 'ken';
function foo () {
console.log(this.name); // 'this' === undefined
}
foo();
추가 예제
var age = 100;
function foo () {
var age = 99;
bar();
}
function bar () {
console.log(this.age);
}
foo();
-
질문
Keehwan Jee
2018.8.1 12:22
4