Ensures a function can only be called once. Subsequent calls will return the result of the first execution.
The function to execute only once.
A new function that expects the exact same parameters as the original.
const initialize = once(() => { console.log("Setup complete!"); return { status: "ready" };});initialize(); // Logs "Setup complete!"initialize(); // Does nothing, just returns { status: "ready" } Copy
const initialize = once(() => { console.log("Setup complete!"); return { status: "ready" };});initialize(); // Logs "Setup complete!"initialize(); // Does nothing, just returns { status: "ready" }
Ensures a function can only be called once. Subsequent calls will return the result of the first execution.