Runs a given method only once, regardless of how many times it's called.

Parameters:
NameTypeDescription
fnfunction

The method or function to execute once.

Since
  • 3.2.1
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