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.0 KB
|
Line | |
---|
1 | var assignValue = require('./_assignValue'),
|
---|
2 | baseAssignValue = require('./_baseAssignValue');
|
---|
3 |
|
---|
4 | /**
|
---|
5 | * Copies properties of `source` to `object`.
|
---|
6 | *
|
---|
7 | * @private
|
---|
8 | * @param {Object} source The object to copy properties from.
|
---|
9 | * @param {Array} props The property identifiers to copy.
|
---|
10 | * @param {Object} [object={}] The object to copy properties to.
|
---|
11 | * @param {Function} [customizer] The function to customize copied values.
|
---|
12 | * @returns {Object} Returns `object`.
|
---|
13 | */
|
---|
14 | function copyObject(source, props, object, customizer) {
|
---|
15 | var isNew = !object;
|
---|
16 | object || (object = {});
|
---|
17 |
|
---|
18 | var index = -1,
|
---|
19 | length = props.length;
|
---|
20 |
|
---|
21 | while (++index < length) {
|
---|
22 | var key = props[index];
|
---|
23 |
|
---|
24 | var newValue = customizer
|
---|
25 | ? customizer(object[key], source[key], key, object, source)
|
---|
26 | : undefined;
|
---|
27 |
|
---|
28 | if (newValue === undefined) {
|
---|
29 | newValue = source[key];
|
---|
30 | }
|
---|
31 | if (isNew) {
|
---|
32 | baseAssignValue(object, key, newValue);
|
---|
33 | } else {
|
---|
34 | assignValue(object, key, newValue);
|
---|
35 | }
|
---|
36 | }
|
---|
37 | return object;
|
---|
38 | }
|
---|
39 |
|
---|
40 | module.exports = copyObject;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.