Skip to content

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

License

Notifications You must be signed in to change notification settings

fabiospampinato/function-once

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published