클래스


클래스

class Car { // 타입스크립트에서 class를 작성할 때 멤버 변수는 미리 선언해야한다. color:string; constructor(color: string) { this.color = color; } start() { console.log("start"); } } const bmw = new Car("red"); 맴버 변수를 미리 선언하지 않는 방법 접근 제한자나 readonly 키워드를 활용하면 된다. // public class Car { constructor(public color: string) { this.color = color; } start() { console.log("start"); } } const bmw = new Car("red"); // readonly class Car { constructor(readonly color: string) { this.color = color; } start() { console.log("start"); } } ...


#TypeScript #접근제한자 #추상클래스 #클래스

원문링크 : 클래스