1. this라나 뭐라나
주요 개념 및 내용
주의 사항
테스트 코드
(function () {
function foo(num) {
console.log("foo : " + num);
this.count++; // 이부분 this 바인딩 되는 객체 확인 (global or foo)
// console.log(this.count); // 확인
}
foo.count = 0;
var i;
for (i = 0; i < 10; i++) {
if (i > 5) {
foo(i); // 0나옴
// foo.call(foo, i); // 4나옴
}
}
console.log(foo.count); // 0, 4
console.log("==========");
function foo2() {
var a = 2;
// this.bar();
bar(); // -> this : global
}
function bar() {
console.log("bar" + this.a); // undefined?
}
foo2(); // 참조 에러
})();Last updated