function-once
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

Function Once

Wraps a function so that it's only ever executed once.

Note: this is always set to undefined and only functions that don't accept any arguments are supported, as using those with a function that's only ever executed once is practically just a footgun. If you need different this or different arguments you should probably use memoization instead.

Install

npm install --save function-once

Usage

import once from 'function-once';

const rand = once (() => Math.random ());

rand (); // => 0.3344627371267874
rand (); // => 0.3344627371267874

License

MIT © Fabio Spampinato

Readme

Keywords

Package Sidebar

Install

npm i function-once

Weekly Downloads

321

Version

3.0.0

License

none

Unpacked Size

3.5 kB

Total Files

9

Last publish

Collaborators

  • fabiospampinato