|
var baseRest = require('./_baseRest'), |
|
eq = require('./eq'), |
|
isIterateeCall = require('./_isIterateeCall'), |
|
keysIn = require('./keysIn'); |
|
|
|
|
|
var objectProto = Object.prototype; |
|
|
|
|
|
var hasOwnProperty = objectProto.hasOwnProperty; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var defaults = baseRest(function(object, sources) { |
|
object = Object(object); |
|
|
|
var index = -1; |
|
var length = sources.length; |
|
var guard = length > 2 ? sources[2] : undefined; |
|
|
|
if (guard && isIterateeCall(sources[0], sources[1], guard)) { |
|
length = 1; |
|
} |
|
|
|
while (++index < length) { |
|
var source = sources[index]; |
|
var props = keysIn(source); |
|
var propsIndex = -1; |
|
var propsLength = props.length; |
|
|
|
while (++propsIndex < propsLength) { |
|
var key = props[propsIndex]; |
|
var value = object[key]; |
|
|
|
if (value === undefined || |
|
(eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) { |
|
object[key] = source[key]; |
|
} |
|
} |
|
} |
|
|
|
return object; |
|
}); |
|
|
|
module.exports = defaults; |
|
|