SOURCE

function cached(fn) {
    const cache = Object.create(null);

    return function cachedFn(str) {
        const hit = cache[str];
        return hit || (cache[str] = fn(str))
    }
}

// 测试
function computed(str) {
    console.log('2000s have passwed');
    return 'a result';
}

const cachedComputed = cached(computed);
console.log(cachedComputed("ss"));

console.log(cachedComputed("ss"));

console.log(cachedComputed("dd"));

console.log(cachedComputed("ee"));
console 命令行工具 X clear

                    
>
console