Skip to content

Latest commit

 

History

History
21 lines (17 loc) · 686 Bytes

README.md

File metadata and controls

21 lines (17 loc) · 686 Bytes

singleton

alt text alt text alt text

Example

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

Changing the inner instance

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