Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
/**
2
* Creates a function that returns `value`.
3
*
4
* @static
5
* @memberOf _
6
* @category Utility
7
* @param {*} value The value to return from the new function.
8
* @returns {Function} Returns the new function.
9
* @example
10
*
11
* var object = { 'user': 'fred' };
12
* var getter = _.constant(object);
13
*
14
* getter() === object;
15
* // => true
16
*/
17
function constant(value) {
18
return function() {
19
return value;
20
};
21
}
22
23
module.exports = constant;
24
25