index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * Code refactored from Mozilla Developer Network:
  3. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  4. */
  5. 'use strict';
  6. function assign(target, firstSource) {
  7. if (target === undefined || target === null) {
  8. throw new TypeError('Cannot convert first argument to object');
  9. }
  10. var to = Object(target);
  11. for (var i = 1; i < arguments.length; i++) {
  12. var nextSource = arguments[i];
  13. if (nextSource === undefined || nextSource === null) {
  14. continue;
  15. }
  16. var keysArray = Object.keys(Object(nextSource));
  17. for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
  18. var nextKey = keysArray[nextIndex];
  19. var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
  20. if (desc !== undefined && desc.enumerable) {
  21. to[nextKey] = nextSource[nextKey];
  22. }
  23. }
  24. }
  25. return to;
  26. }
  27. function polyfill() {
  28. if (!Object.assign) {
  29. Object.defineProperty(Object, 'assign', {
  30. enumerable: false,
  31. configurable: true,
  32. writable: true,
  33. value: assign
  34. });
  35. }
  36. }
  37. module.exports = {
  38. assign: assign,
  39. polyfill: polyfill
  40. };