SOURCE

class ComputeStore {
    constructor() {
        this.store = new Map()
    }
    get(func, ...args) {

        const params = JSON.stringify(args)

        if (!this.store.has(func)) {
            const result = func(...args)
            const paramsMap = new Map()

            paramsMap.set(params, result)
            this.store.set(func, paramsMap)
            return result
        }

        const paramsMap = this.store.get(func)

        if (!paramsMap.has(params)) {
            const result = func(...args)

            paramsMap.set(params, result)
            return result
        }
        return paramsMap.get(params)
    }
}
let test = new ComputeStore()
let func = (e) => e
console.log(test.get(func, 1, { a: 1 }))

console.log(test.get(func, 2, { a: 2 }))
console.log(test.get(func, 2, { a: 2 }))

console.log(test.get(func, 3, 3))
console.log(test.get(func, 3, 3))
console.log(test.get(func, 3, 3))

console.log(test.get(func, 4))
console.log(test.get(func, 4))
console.log(test.get(func, 4))
console.log(test.get(func, 4))
console.log(test.store)
console 命令行工具 X clear

                    
>
console