Skip to content

memDecorator

memDecorator(options?): (target: any, propertyKey: any, descriptor: any) => void

参数

NameType
optionsObject

返回值

fn

A decorator to memoize class methods or static class methods.

▸ (target, propertyKey, descriptor): void

参数
NameType
targetany
propertyKeyany
descriptorany
返回值

void

示例

import {memDecorator} from 'mem';

class Example {
    index = 0

    @memDecorator()
    counter() {
        return ++this.index;
    }
}

class ExampleWithOptions {
    index = 0

    @memDecorator({maxAge: 1000})
    counter() {
        return ++this.index;
    }
}

源码

memoize.js