Last change
on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
528 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | /**
|
---|
| 2 | * Creates a function that returns `value`.
|
---|
| 3 | *
|
---|
| 4 | * @static
|
---|
| 5 | * @memberOf _
|
---|
| 6 | * @since 2.4.0
|
---|
| 7 | * @category Util
|
---|
| 8 | * @param {*} value The value to return from the new function.
|
---|
| 9 | * @returns {Function} Returns the new constant function.
|
---|
| 10 | * @example
|
---|
| 11 | *
|
---|
| 12 | * var objects = _.times(2, _.constant({ 'a': 1 }));
|
---|
| 13 | *
|
---|
| 14 | * console.log(objects);
|
---|
| 15 | * // => [{ 'a': 1 }, { 'a': 1 }]
|
---|
| 16 | *
|
---|
| 17 | * console.log(objects[0] === objects[1]);
|
---|
| 18 | * // => true
|
---|
| 19 | */
|
---|
| 20 | function constant(value) {
|
---|
| 21 | return function() {
|
---|
| 22 | return value;
|
---|
| 23 | };
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | module.exports = constant;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.