shim.js 500 B

1234567891011121314151617181920212223
  1. "use strict";
  2. var keys = require("../keys")
  3. , value = require("../valid-value")
  4. , max = Math.max;
  5. module.exports = function (dest, src /*, …srcn*/) {
  6. var error, i, length = max(arguments.length, 2), assign;
  7. dest = Object(value(dest));
  8. assign = function (key) {
  9. try {
  10. dest[key] = src[key];
  11. } catch (e) {
  12. if (!error) error = e;
  13. }
  14. };
  15. for (i = 1; i < length; ++i) {
  16. src = arguments[i];
  17. keys(src).forEach(assign);
  18. }
  19. if (error !== undefined) throw error;
  20. return dest;
  21. };