implementation.js 1.3 KB

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