javascript 이론/객체지향 프로그래밍
1. constructor
멍식이
2022. 10. 5. 16:07
function Person(name, first, second) {
this.name = name;
this.first = first;
this.second = second;
this.sum = function () {
return this.first + this.second;
};
}
const kim = new Person("kim", 10, 20);
console.log(kim.sum());
1. this
this란 (객체안에속한)메서드 입장에서 자신이 속한 객체 자체를 지칭하는, '자신이 몸담고 있는 소속'을 가리키는 특수한 키워드 이다.
2. new
객체를 생성하는 생성자 함수 (constructor)