<aside> 📌 자바스크립트는 명령형, 함수형, 프로토타입 기반 객체지향 프로그래밍을 지원하는 멀티 패러다임 프로그래밍 언어다.
</aside>
ex1 ) 이름과 주소 속성을 갖는 person이라는 객체 만들기
const person = {
name: 'Lee',
address: 'Seoul'
}
ex 2 ) 반지름 속성과 원의 지름, 둘레, 넓이를 구하는 속성을 갖는 circle이라는 객체 만들기
const circle = {
radius: 10,
getDiameter() {
return 2 * this.radius;
}
getPerimeter() {
return 2 * Math.PI * this.radius;
}
getArea() {
return Math.PI * this.radius ** 2;
}
}
// 생성자 함수
function Circle(radius) {
this.radius = radius;
this.getArea = function () {
return Math.PI * this.radius ** 2;
};
}
// 인스턴스 생성
const circle1 = new Circle(1);
const circle2 = new Circle(2);
// 인스턴스의 getArea 메서드는 동일하지 않음
console.log(circle1.getArea === circle2.getArea); // false