1
|
'use strict';
|
2
|
|
3
|
// modified from https://github.com/es-shims/es6-shim
|
4
|
var keys = require('object-keys');
|
5
|
var bind = require('function-bind');
|
6
|
var canBeObject = function (obj) {
|
7
|
return typeof obj !== 'undefined' && obj !== null;
|
8
|
};
|
9
|
var hasSymbols = require('has-symbols/shams')();
|
10
|
var toObject = Object;
|
11
|
var push = bind.call(Function.call, Array.prototype.push);
|
12
|
var propIsEnumerable = bind.call(Function.call, Object.prototype.propertyIsEnumerable);
|
13
|
var originalGetSymbols = hasSymbols ? Object.getOwnPropertySymbols : null;
|
14
|
|
15
|
module.exports = function assign(target, source1) {
|
16
|
if (!canBeObject(target)) { throw new TypeError('target must be an object'); }
|
17
|
var objTarget = toObject(target);
|
18
|
var s, source, i, props, syms, value, key;
|
19
|
for (s = 1; s < arguments.length; ++s) {
|
20
|
source = toObject(arguments[s]);
|
21
|
props = keys(source);
|
22
|
var getSymbols = hasSymbols && (Object.getOwnPropertySymbols || originalGetSymbols);
|
23
|
if (getSymbols) {
|
24
|
syms = getSymbols(source);
|
25
|
for (i = 0; i < syms.length; ++i) {
|
26
|
key = syms[i];
|
27
|
if (propIsEnumerable(source, key)) {
|
28
|
push(props, key);
|
29
|
}
|
30
|
}
|
31
|
}
|
32
|
for (i = 0; i < props.length; ++i) {
|
33
|
key = props[i];
|
34
|
value = source[key];
|
35
|
if (propIsEnumerable(source, key)) {
|
36
|
objTarget[key] = value;
|
37
|
}
|
38
|
}
|
39
|
}
|
40
|
return objTarget;
|
41
|
};
|