Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- node
- flex-grow
- Engoo
- regExp
- Express
- module wrapper function
- close together
- 정규표현식
- shit-christmas
- Node.js
- flex-shrink
- express-handlebars
- flex-basis
- select by attribute
- Prototype
- css grid
- ajax
- Sass
- css
- css variables
- flexbox
- img 확대
- css 오버레이
- JS
- es6
- Object.create
- 무료 백엔드 배포
- improve-iq-by-up-to-10%!
- 디자인패턴
- just-one-small-sip
Archives
- Today
- Total
ES6 class Inheritance 본문
class 키워드를 이용했을 때 상속 구현 방법을 알아보자.
extends 라는 키워드를 이용해 상속받을 클래스를 기재하고, 해당 클래스를 상속받은 클래스의 생성자에 super()를 이용해 부모 클래스의 생성자를 호출할 수 있다.
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
greeting() {
return `Hello there ${this.firstName} ${this.lastName}`;
}
}
class Customer extends Person {
constructor(firstName, lastName, phone, membership) {
super(firstName, lastName); // Calls parent class constructor
this.phone = phone;
this.membership = membership;
}
static getMembershipCost() {
return 500;
}
}
const jian = new Customer("jian", "dev", "555-555-8555", "Standard");
console.log(jian.greeting());
console.log(Customer.getMembershipCost());
'2021 프론트 엔드 로드맵 따라가기 > JS' 카테고리의 다른 글
비동기(Asynchronous) 프로그래밍이란 (0) | 2021.06.06 |
---|---|
ES5에서 static 메서드를 선언하기 (0) | 2021.06.06 |
ES6 class (0) | 2021.06.05 |
[중요] Prototypal inheritance (0) | 2021.06.05 |
Prototype (0) | 2021.06.05 |
Comments