项目作者: grevend

项目描述 :
singleton deno module
高级语言: TypeScript
项目地址: git://github.com/grevend/singleton.git
创建时间: 2021-03-15T09:03:49Z
项目社区:https://github.com/grevend/singleton

开源协议:MIT License

下载


singleton

alt text
alt text
alt text

Example

  1. const rand = singleton(Math.random);
  2. const first = rand.getInstance();
  3. const second = rand.getInstance(); // first === second

Changing the inner instance

  1. const str = singleton(() => "a");
  2. const first = rand.getInstance(); // "a"
  3. str.setInstance("b");
  4. const second = rand.getInstance(); // "b", first !== second