Runs a given method only once, regardless of how many times it's called.
Parameters:
Name | Type | Description |
---|---|---|
fn | function | The method or function to execute once. |
- Since
- 3.2.1
- Source
Returns:
A new function that, when called, executes the provided function only once.
- Type:
- function
Example
const initializeLogging = initOnce(() => {
console.log('Logging initialized');
});
initializeLogging(); // Logs 'Logging initialized'
initializeLogging(); // No output, as it's already initialized