this
생성자에서 this
function Person(name) {
this.name = name;
this.getName = function() {
return this.name;
}
}
const p1 = new Person('JS');
console.log(p1.getName()); //JS
호출 방식에 따라 달라지는 this
function Person(name) {
this.name = name;
this.getName = function() {
return this.name;
}
}
const p1 = new Person('JS');
const getName = p1.getName;
console.log(getName()); //??
일반 함수에서 this
콜백 함수의 this
Last updated