object.assign.polyfill.js 1.1 KB

1234567891011121314151617181920212223242526272829
  1. if (typeof Object.assign !== 'function') {
  2. // Must be writable: true, enumerable: false, configurable: true
  3. Object.defineProperty(Object, 'assign', {
  4. value: function assign(target, varArgs) { // .length of function is 2
  5. 'use strict';
  6. if (target == null) { // TypeError if undefined or null
  7. throw new TypeError('Cannot convert undefined or null to object');
  8. }
  9. var to = Object(target);
  10. for (var index = 1; index < arguments.length; index++) {
  11. var nextSource = arguments[index];
  12. if (nextSource != null) { // Skip over if undefined or null
  13. for (var nextKey in nextSource) {
  14. // Avoid bugs when hasOwnProperty is shadowed
  15. if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
  16. to[nextKey] = nextSource[nextKey];
  17. }
  18. }
  19. }
  20. }
  21. return to;
  22. },
  23. writable: true,
  24. configurable: true
  25. });
  26. }