Last change
on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | var baseUpdate = require('./_baseUpdate'),
|
---|
2 | castFunction = require('./_castFunction');
|
---|
3 |
|
---|
4 | /**
|
---|
5 | * This method is like `_.set` except that accepts `updater` to produce the
|
---|
6 | * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
|
---|
7 | * is invoked with one argument: (value).
|
---|
8 | *
|
---|
9 | * **Note:** This method mutates `object`.
|
---|
10 | *
|
---|
11 | * @static
|
---|
12 | * @memberOf _
|
---|
13 | * @since 4.6.0
|
---|
14 | * @category Object
|
---|
15 | * @param {Object} object The object to modify.
|
---|
16 | * @param {Array|string} path The path of the property to set.
|
---|
17 | * @param {Function} updater The function to produce the updated value.
|
---|
18 | * @returns {Object} Returns `object`.
|
---|
19 | * @example
|
---|
20 | *
|
---|
21 | * var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
---|
22 | *
|
---|
23 | * _.update(object, 'a[0].b.c', function(n) { return n * n; });
|
---|
24 | * console.log(object.a[0].b.c);
|
---|
25 | * // => 9
|
---|
26 | *
|
---|
27 | * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
|
---|
28 | * console.log(object.x[0].y.z);
|
---|
29 | * // => 0
|
---|
30 | */
|
---|
31 | function update(object, path, updater) {
|
---|
32 | return object == null ? object : baseUpdate(object, path, castFunction(updater));
|
---|
33 | }
|
---|
34 |
|
---|
35 | module.exports = update;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.