1 | 'use strict';
|
---|
2 |
|
---|
3 | // modified from https://github.com/es-shims/es6-shim
|
---|
4 | var objectKeys = require('object-keys');
|
---|
5 | var hasSymbols = require('has-symbols/shams')();
|
---|
6 | var callBound = require('call-bind/callBound');
|
---|
7 | var toObject = Object;
|
---|
8 | var $push = callBound('Array.prototype.push');
|
---|
9 | var $propIsEnumerable = callBound('Object.prototype.propertyIsEnumerable');
|
---|
10 | var originalGetSymbols = hasSymbols ? Object.getOwnPropertySymbols : null;
|
---|
11 |
|
---|
12 | // eslint-disable-next-line no-unused-vars
|
---|
13 | module.exports = function assign(target, source1) {
|
---|
14 | if (target == null) { throw new TypeError('target must be an object'); }
|
---|
15 | var to = toObject(target); // step 1
|
---|
16 | if (arguments.length === 1) {
|
---|
17 | return to; // step 2
|
---|
18 | }
|
---|
19 | for (var s = 1; s < arguments.length; ++s) {
|
---|
20 | var from = toObject(arguments[s]); // step 3.a.i
|
---|
21 |
|
---|
22 | // step 3.a.ii:
|
---|
23 | var keys = objectKeys(from);
|
---|
24 | var getSymbols = hasSymbols && (Object.getOwnPropertySymbols || originalGetSymbols);
|
---|
25 | if (getSymbols) {
|
---|
26 | var syms = getSymbols(from);
|
---|
27 | for (var j = 0; j < syms.length; ++j) {
|
---|
28 | var key = syms[j];
|
---|
29 | if ($propIsEnumerable(from, key)) {
|
---|
30 | $push(keys, key);
|
---|
31 | }
|
---|
32 | }
|
---|
33 | }
|
---|
34 |
|
---|
35 | // step 3.a.iii:
|
---|
36 | for (var i = 0; i < keys.length; ++i) {
|
---|
37 | var nextKey = keys[i];
|
---|
38 | if ($propIsEnumerable(from, nextKey)) { // step 3.a.iii.2
|
---|
39 | var propValue = from[nextKey]; // step 3.a.iii.2.a
|
---|
40 | to[nextKey] = propValue; // step 3.a.iii.2.b
|
---|
41 | }
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | return to; // step 4
|
---|
46 | };
|
---|