Skip to Content
자바스크립트 + 리액트 디자인 패턴
book

자바스크립트 + 리액트 디자인 패턴

by 애디 오스마니(Addy Osmani), 윤창식
August 2024
Beginner to intermediate
384 pages
7h 38m
Korean
Hanbit Media, Inc.
Content preview from 자바스크립트 + 리액트 디자인 패턴
76
자바스크립트 + 리액트 디자인 패턴
// 상속받은 속성 값을 가져옵니다.
console.log(driver.dateOfBirth);
// 할당한 속성 값을 가져옵니다.
console.log(driver.topSpeed);
7.2.2
생성자의 기본 특징
앞선
5
장에서 다뤘던 것처럼
ES2015
에 도입된 자바스크립트의 클래스는 객체 템플릿을 정
의하고 캡슐화
encapsulation
및 상속을 구현할 수 있게 했습니다.
요약하자면, 클래스는 새 객체를 초기화하는
constructor
()
라는 이름의 메서드를 가지
고 있어야 합니다. 또한
new
키워드는 생성자를 호출할 수 있으며, 생성자 내부에서 사용된
this
키워드는 새로 생성된 해당 객체를 가리킵니다. 다음 예제를 통해 생성자의 기본 특징
에 대해 알아봅시다.
class Car {
constructor(model, year, miles) {
this.model = model;
this.year = year;
this.miles = miles;
}
toString() {
return `${this.model} has done ${this.miles} miles`;
}
}
// 사용법:
// 새로운 Car 인스턴스 생성
let civic = new Car('Honda Civic', 2009, 20000);
let mondeo ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

AI를 위한 필수 수학

AI를 위한 필수 수학

할라 넬슨
클라우드 엔지니어를 위한 97가지 조언

클라우드 엔지니어를 위한 97가지 조언

Emily Freeman, Nathen Harvey, 정기훈(Jung Ki Hun)

Publisher Resources

ISBN: 9791169212571