1 | var baseRest = require('./_baseRest'),
|
2 | eq = require('./eq'),
|
3 | isIterateeCall = require('./_isIterateeCall'),
|
4 | keysIn = require('./keysIn');
|
5 |
|
6 |
|
7 | var objectProto = Object.prototype;
|
8 |
|
9 |
|
10 | var hasOwnProperty = objectProto.hasOwnProperty;
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | var defaults = baseRest(function(object, sources) {
|
34 | object = Object(object);
|
35 |
|
36 | var index = -1;
|
37 | var length = sources.length;
|
38 | var guard = length > 2 ? sources[2] : undefined;
|
39 |
|
40 | if (guard && isIterateeCall(sources[0], sources[1], guard)) {
|
41 | length = 1;
|
42 | }
|
43 |
|
44 | while (++index < length) {
|
45 | var source = sources[index];
|
46 | var props = keysIn(source);
|
47 | var propsIndex = -1;
|
48 | var propsLength = props.length;
|
49 |
|
50 | while (++propsIndex < propsLength) {
|
51 | var key = props[propsIndex];
|
52 | var value = object[key];
|
53 |
|
54 | if (value === undefined ||
|
55 | (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
|
56 | object[key] = source[key];
|
57 | }
|
58 | }
|
59 | }
|
60 |
|
61 | return object;
|
62 | });
|
63 |
|
64 | module.exports = defaults;
|