home
자바
home
🔥

#4.5

#4.5 Polymorphism
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 stringSotrage = new LocalStorage<string>(); stringStorage.get('key'); const booleansStorage = new LocalStorage<boolean>(); booleansStorage.get('jjw');
TypeScript
복사