Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "utils/memoize/docs/types/index.d"

Index

Functions

Functions

Export assignment memoize

  • memoize(fcn: Function, hashFunction?: Function): Function
  • Returns a memoized function.

    Notes

    • The function does not set the length property of the returned function. Accordingly, the returned function length is always zero.
    • The evaluation context is always null.
    • The function serializes provided arguments as a string and stores results using the string as an identifier. To use a custom hash function, provide a hash function argument.

    Parameters

    • fcn: Function

      function to memoize

    • Optional hashFunction: Function

      function to map a set of arguments to a single value identifying that set

    Returns Function

    memoized function

    Example

    function factorial( n ) {
        var prod;
        var i;
        prod = 1;
        for ( i = n; i > 1; i-- ) {
            prod *= i;
        }
        return prod;
    }
    
    var memoized = memoize( factorial );
    
    var v = memoized( 5 );
    // returns 120
    
    v = memoized( 5 );
    // returns 120