HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
📝
프론트엔드 스쿨 교안(1기)
/
📝
Javascript
/
📝
Class
📝

Class

// __proto__ (비공식) 문법이에요. // prototype 공식입니다. // __proto__는 [[Prototype]]의 getter·setter // getter는? // setter는? class Human { constructor(name) { this.hp = 100; this.mp = 100; this.speed = 0; this.name = name; } attack(speed) { this.speed = speed; console.log(`${this.name}이 ${this.speed}의 속도로 공격합니다.`); } stop() { this.speed = 0; console.log(`${this.name}이 공격을 멈췄습니다.`); } } let 상점주인 = new Human("이호준"); let 대장장이 = new Human("홍길동"); class Hero extends Human{ skill() { console.log(`${this.name}가 스킬을 사용했습니다!`); } stop() { super.stop(); // 부모 클래스의 stop을 호출해 멈추고 this.skill(); // skill 사용 } } let 영웅 = new Hero("이호준"); 영웅.attack(5); 영웅.stop();
 
자세한 내용은 아래 문서를 참고해주세요.
클래스와 기본 문법
클래스는 객체 지향 프로그래밍에서 특정 객체를 생성하기 위해 변수와 메소드를 정의하는 일종의 틀로, 객체를 정의하기 위한 상태(멤버 변수)와 메서드(함수)로 구성된다. 실무에선 사용자나 물건같이 동일한 종류의 객체를 여러 개 생성해야 하는 경우가 잦습니다. 이럴 때 new 연산자와 생성자 함수에서 배운 new function 을 사용할 수 있습니다.
클래스와 기본 문법
https://ko.javascript.info/class
클래스와 기본 문법