1.0.2 • Published 5 years ago

lazy-decorator v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

lazy decorator

概要

node で scala の lazy val を再現しました。

1 度目呼び出し時に値を計算し、2 度目以降は 1 度目にキャッシュした値を呼び出すように作っています。

実装例

import { lazy } from "lazy-decorator";

class Foo {
  @lazy public random() {
    return Math.round(Math.random() * 100);
  }
}

const foo = new Foo();
console.log(foo.random());
console.log(foo.random());

output

77
77
1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago