Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
var before = require('./before');
2
3
/**
4
* Creates a function that is restricted to invoking `func` once. Repeat calls
5
* to the function return the value of the first call. The `func` is invoked
6
* with the `this` binding and arguments of the created function.
7
*
8
* @static
9
* @memberOf _
10
* @category Function
11
* @param {Function} func The function to restrict.
12
* @returns {Function} Returns the new restricted function.
13
* @example
14
*
15
* var initialize = _.once(createApplication);
16
* initialize();
17
* initialize();
18
* // `initialize` invokes `createApplication` once
19
*/
20
function once(func) {
21
return before(2, func);
22
}
23
24
module.exports = once;
25
26