2020-03-31 20:42:07 +08:00
|
|
|
'use strict';
|
|
|
|
|
2020-03-31 20:57:48 +08:00
|
|
|
var isObject = require('is-extendable');
|
2020-03-31 20:42:07 +08:00
|
|
|
|
2020-03-31 20:57:48 +08:00
|
|
|
module.exports = function extend(o/*, objects*/) {
|
|
|
|
if (!isObject(o)) { o = {}; }
|
|
|
|
|
|
|
|
var len = arguments.length;
|
|
|
|
for (var i = 1; i < len; i++) {
|
|
|
|
var obj = arguments[i];
|
|
|
|
|
|
|
|
if (isObject(obj)) {
|
|
|
|
assign(o, obj);
|
2020-03-31 20:42:07 +08:00
|
|
|
}
|
|
|
|
}
|
2020-03-31 20:57:48 +08:00
|
|
|
return o;
|
2020-03-31 20:42:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
function assign(a, b) {
|
|
|
|
for (var key in b) {
|
|
|
|
if (hasOwn(b, key)) {
|
|
|
|
a[key] = b[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the given `key` is an own property of `obj`.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function hasOwn(obj, key) {
|
|
|
|
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
|
|
}
|