UNPKG

@miyauci/memo

Version:

Memoization tools, TC39 proposal-function-memo implementation

24 lines (23 loc) 638 B
// Copyright © 2023 Tomoki Miyauchi. All rights reserved. MIT license. // This module is browser compatible. // deno-lint-ignore-file ban-types no-explicit-any /** * Polyfill affects the global object. You must be very careful when using it. * * @example * ```ts * import "https://deno.land/x/memoization@$VERSION/polyfill.ts"; * * const fib = ((num: number): number => { * if (num < 2) return num; * * return fib(num - 1) + fib(num - 2); * }).memo(); * * fib(1000); * ``` */ import { memo as _memo } from "./memo.js"; Function.prototype.memo = function memo(cache, keying) { return _memo(this, cache, keying); };