xszi / javascript-algorithms

算法修炼中...
5 stars 0 forks source link

百度&阿里编程题:模拟实现一个 localStorage #2

Open xszi opened 4 years ago

xszi commented 4 years ago
class LocalStorageSimulation {
    constructor() {
        this.storage = {}
    }
    getItem(key) {
        return this.storage[key]
    }
    setItem(key, value) {
        this.storage[key] = value
    }
    deleteItem(key) {
        delete this.storage[key]
    }
    clear() {
        this.storage = {}
    }
}