Object.es6.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * Copyright 2013-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. * @provides Object.es6
  9. * @polyfill
  10. */
  11. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign
  12. if (!Object.assign) {
  13. Object.assign = function(target, sources) {
  14. if (target === null || target === undefined) {
  15. throw new TypeError('Object.assign target cannot be null or undefined');
  16. }
  17. var to = Object(target);
  18. var hasOwnProperty = Object.prototype.hasOwnProperty;
  19. for (var nextIndex = 1; nextIndex < arguments.length; nextIndex++) {
  20. var nextSource = arguments[nextIndex];
  21. if (nextSource === null || nextSource === undefined) {
  22. continue;
  23. }
  24. var from = Object(nextSource);
  25. // We don't currently support accessors nor proxies. Therefore this
  26. // copy cannot throw. If we ever supported this then we must handle
  27. // exceptions and side-effects.
  28. for (var key in from) {
  29. if (hasOwnProperty.call(from, key)) {
  30. to[key] = from[key];
  31. }
  32. }
  33. }
  34. return to;
  35. };
  36. }