SOURCE

class MyCookie {
    constructor(cookies = document.cookie) {
        this.cookies = cookies
        this.cookieData = {}
        this._initCookieData()
    }
    _initCookieData() {
        let cookieArr = this.cookies.split('; ')
        cookieArr.forEach((keyVal, index) => {
            const [keyName, value] = keyVal.split('=')
            this.cookieData[keyName] = value
        })
    }
    getAll() {
        return this._initCookieData()
    }
    get(keyName) {
        return this.cookieData[keyName] || null
    }
}

const myCookie = new MyCookie()
console.log(myCookie.getAll())
console 命令行工具 X clear

                    
>
console