728x90
접근 제어자(Acess Modifier)
- public : default, 어디서나 자유롭게 접근 가능
- protected : 나와 파생된 후손 클래스 내에서 접근 가능
- private : 클래스 내에서만 접근 가능
class userA {
constructor(public first : string, protected last : string,private age : number) {
this.first = first
this.last = last
this.age = age
}
}
class UserB extends UserA() {
getAge() {
return `${this.first} ${this.last} is ${this.age}` //first, last 사용 가능 but age는 접근 불간ㅇ
}
}
const neo = new UserA('Neo', 'Tom', 12)
neo.last //불가
728x90
'FE > Typescipt' 카테고리의 다른 글
[Typescript] tsconfing.json 구성 옵션 (0) | 2023.09.01 |
---|---|
[Typescript] Generic (0) | 2023.09.01 |
[Typescript] 함수 (0) | 2023.09.01 |
[Typescript] Interface (0) | 2023.09.01 |
[Typescript] Type (0) | 2023.09.01 |