18 lines
651 B
JavaScript
18 lines
651 B
JavaScript
var isNil = require('./isNil');
|
|
var assert = require('./assert');
|
|
|
|
// safe mixin, cannot override props unless specified
|
|
module.exports = function mixin(target, source, overwrite) {
|
|
if (isNil(source)) { return target; }
|
|
for (var k in source) {
|
|
if (source.hasOwnProperty(k)) {
|
|
if (overwrite !== true) {
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
assert(!target.hasOwnProperty(k) || target[k] === source[k], function () { return 'Invalid call to mixin(target, source, [overwrite]): cannot overwrite property "' + k + '" of target object'; });
|
|
}
|
|
}
|
|
target[k] = source[k];
|
|
}
|
|
}
|
|
return target;
|
|
}; |