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 bind = require('function-bind');
  5. var canBeObject = function (obj) {
  6. return typeof obj !== 'undefined' && obj !== null;
  7. };
  8. var hasSymbols = require('has-symbols/shams')();
  9. var toObject = Object;
  10. var push = bind.call(Function.call, Array.prototype.push);
  11. var propIsEnumerable = bind.call(Function.call, Object.prototype.propertyIsEnumerable);
  12. var originalGetSymbols = hasSymbols ? Object.getOwnPropertySymbols : null;
  13. module.exports = function assign(target, source1) {
  14. if (!canBeObject(target)) { throw new TypeError('target must be an object'); }
  15. var objTarget = toObject(target);
  16. var s, source, i, props, syms, value, key;
  17. for (s = 1; s < arguments.length; ++s) {
  18. source = toObject(arguments[s]);
  19. props = keys(source);
  20. var getSymbols = hasSymbols && (Object.getOwnPropertySymbols || originalGetSymbols);
  21. if (getSymbols) {
  22. syms = getSymbols(source);
  23. for (i = 0; i < syms.length; ++i) {
  24. key = syms[i];
  25. if (propIsEnumerable(source, key)) {
  26. push(props, key);
  27. }
  28. }
  29. }
  30. for (i = 0; i < props.length; ++i) {
  31. key = props[i];
  32. value = source[key];
  33. if (propIsEnumerable(source, key)) {
  34. objTarget[key] = value;
  35. }
  36. }
  37. }
  38. return objTarget;
  39. };