
this?
method 내부에서, 객체를 접근하는 방법이다.
let user = {
name: "John",
age: 30,
sayHi() {
// 'this'는 '현재 객체'를 나타냅니다.
//alert(user.name)의 의미.
alert(this.name);
}
};
user.sayHi(); // John
this는 현재 포함되어있는 객체 user를 뜻한다.
javascript.info
this는 호출된 시점에서 값이 결정된다.
alert(user.ref.name)에서 값이 결정되는데, 결정해줄 객체가 없다. undefined가 들어가고, 오류가 난다.