■ 접근 제한자 종류 : public, private, protect
지정하지 않으면 모두 public
■ 생성자
constructor 라는 예약어를 사용함.
특이점은 생성자에서 멤버 변수를 선언할 수 있다.
예)
class School {
constructor(public schoolName: string, public schoolAddress?: string) {}
}
let myschool : School = new School('멋진고등학교', '대전시 서구 용문동')
console.log(myschool)
인터페이스를 구현한 클래스 예
interface ISchool {
schoolName : string
schoolAddress : string
}
class School implements ISchool {
constructor(public schoolName: string, public schoolAddress: string) {}
}
let mySchool : School = new School('멋진고', '대전시 서구 용문동')
console.log(mySchool)
■ 추상클래스
예)
abstract class AbstractSchool {
abstract schoolName : string
constructor(public schoolAddress : number) {}
}
class School extends AbstractSchool {
constructor(public schoolName: string, schoolAddress: string) {
super(schoolAddress)
}
}
let mySchool : School = new School('멋진고', '대전시 서구 용문동')
console.log(mySchool)
■ 정적 메서드
예)
class Interest {
static interestRate = 3.5
}
let shinhanBankIR = Interest.interestRate
'IT > TypeScript' 카테고리의 다른 글
클로저(closure) - 유효범위 의미 (0) | 2022.10.26 |
---|---|
잔여 연산자(rest operator)와 전개 연산자(spread operator) (0) | 2022.10.21 |
타입주석(type annotation), 타입추론(type inference), 선택속성(optional property), 템플릿 문자열(template string) (0) | 2022.10.19 |
node 패키지 설치하고, 소스파일 생성하기 (프로젝트 생성 full 버전) (0) | 2022.10.14 |
@types/ 의 의미 - 컴파일러가 라이브러리 함수 사용 검증용 (0) | 2022.10.14 |
댓글