BigW Consortium Gitlab

object.js 872 Bytes
Newer Older
1
/* eslint-disable no-restricted-syntax */
2

3 4 5
// Adapted from https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill
if (typeof Object.assign !== 'function') {
  Object.assign = function assign(target, ...args) {
6 7 8 9
    if (target == null) { // TypeError if undefined or null
      throw new TypeError('Cannot convert undefined or null to object');
    }

10
    const to = Object(target);
11

12 13
    for (let index = 0; index < args.length; index += 1) {
      const nextSource = args[index];
14 15

      if (nextSource != null) { // Skip over if undefined or null
16
        for (const nextKey in nextSource) {
17 18 19 20 21 22 23 24 25 26
          // Avoid bugs when hasOwnProperty is shadowed
          if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
            to[nextKey] = nextSource[nextKey];
          }
        }
      }
    }
    return to;
  };
}