Polymorphism
- λ€νμ±μ λ€λ₯Έ λͺ¨μμ μ½λλ₯Ό κ°μ§ μ μκ² ν΄μ£Όλ κ²μ΄λ€.
- λ€νμ±μ μ΄λ£° μ μλ λ°©λ²μ μ λ€λ¦μ μ¬μ©νλ κ±°λ€.
- μ λ€λ¦μ placeholder νμ μ μ¬μ©ν μ μλλ‘ νλ€.
- λκ° λλ©΄ νμ μ€ν¬λ¦½νΈλ placeholder νμ μ concrete νμ μΌλ‘ λ°κΏμ€ κ²μ΄λ€.
interface SStorage<T> {
[key:string]:T
}
class LocalStorage<T> {
private storage: SStorage<T> = {}
set(key:string, value:T){
this.storage[key] = value;
}
remove(key:string){
delete this.storage[key]
}
get(key:string):T {
return this.storage[key]
}
clear(){
this.storage = {}
}
}
const stringsStorage = new LocalStorage<string>()
stringsStorage.get("cat")
stringsStorage.set("hello", "how are you")
const booleansStorage = new LocalStorage<boolean>()
booleansStorage.get("xxx")
booleansStorage.set("hello", true)
stringsStorage.get
stringsStorage.set
booleansStorage.get
booleansStorage.set
'π€ Language > π¦ TypeScript' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
TS. λΈλ‘μ²΄μΈ Blockchain (0) | 2022.07.11 |
---|---|
TS. Interfaces (0) | 2022.06.29 |
TS. Classes (0) | 2022.06.29 |
TS. ν¨μ Functions (0) | 2022.06.27 |
TS. readonly type μ½κΈ° μ μ© νμ (0) | 2022.06.21 |