1.手写一个memoize函数
function getPi(r){ console.log('执行了') return Math.PI * r * r; } function memorize(fn){ let cache = {} return function(){ let str = JSON.stringify(arguments) cache[str] = cache[str] || fn.apply(null, arguments) return cache[str] } } let getCount = memorize(getPi) console.log(getCount(4)) console.log(getCount(4)) console.log(getCount(4))