once source npm
_.once(func)
Creates a function that is restricted to invoking func
once. Repeat calls
to the function return the value of the first call. The func
is invoked
with the this
binding and arguments of the created function.
Arguments
- func (Function)
The function to restrict.
Returns (Function)
Returns the new restricted function.
Example
var initialize = _.once(createApplication);
initialize();
initialize();
// `initialize` invokes `createApplication` once