@miyauci/memo
Version:
Memoization tools, TC39 proposal-function-memo implementation
26 lines (25 loc) • 726 B
JavaScript
;
// Copyright © 2023 Tomoki Miyauchi. All rights reserved. MIT license.
// This module is browser compatible.
Object.defineProperty(exports, "__esModule", { value: true });
// 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);
* ```
*/
const memo_js_1 = require("./memo.js");
Function.prototype.memo = function memo(cache, keying) {
return (0, memo_js_1.memo)(this, cache, keying);
};