Closed liby closed 2 years ago
ch05-any/item-40-hide-unsafe-casts/hide-unsafe-casts-04.ts
Maybe it would be better to change the name of the function to memorize. cacheLast always sounds confusing.
memorize
cacheLast
function cacheLast<T extends Function>(fn: T): T { let lastArgs: any[]|null = null; let lastResult: any; return function(...args: any[]) { if (!lastArgs || !shallowEqual(lastArgs, args)) { lastResult = fn(...args); lastArgs = args; } return lastResult; } as unknown as T; }
Is it better to use JSON.stringify(args) instead of (lastArgs, args) function?
JSON.stringify(args)
(lastArgs, args)
It's not important.
ch05-any/item-40-hide-unsafe-casts/hide-unsafe-casts-04.ts
Maybe it would be better to change the name of the function to
memorize
.cacheLast
always sounds confusing.Is it better to use
JSON.stringify(args)
instead of(lastArgs, args)
function?