main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
729 bytes
|
Line | |
---|
1 | function override(source1, source2) {
|
---|
2 | var target = {};
|
---|
3 | var key1;
|
---|
4 | var key2;
|
---|
5 | var item;
|
---|
6 |
|
---|
7 | for (key1 in source1) {
|
---|
8 | item = source1[key1];
|
---|
9 |
|
---|
10 | if (Array.isArray(item)) {
|
---|
11 | target[key1] = item.slice(0);
|
---|
12 | } else if (typeof item == 'object' && item !== null) {
|
---|
13 | target[key1] = override(item, {});
|
---|
14 | } else {
|
---|
15 | target[key1] = item;
|
---|
16 | }
|
---|
17 | }
|
---|
18 |
|
---|
19 | for (key2 in source2) {
|
---|
20 | item = source2[key2];
|
---|
21 |
|
---|
22 | if (key2 in target && Array.isArray(item)) {
|
---|
23 | target[key2] = item.slice(0);
|
---|
24 | } else if (key2 in target && typeof item == 'object' && item !== null) {
|
---|
25 | target[key2] = override(target[key2], item);
|
---|
26 | } else {
|
---|
27 | target[key2] = item;
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | return target;
|
---|
32 | }
|
---|
33 |
|
---|
34 | module.exports = override;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.