mixin.js 879 B

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. var value = require("./valid-value")
  3. , defineProperty = Object.defineProperty
  4. , getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor
  5. , getOwnPropertyNames = Object.getOwnPropertyNames
  6. , getOwnPropertySymbols = Object.getOwnPropertySymbols;
  7. module.exports = function (target, source) {
  8. var error, sourceObject = Object(value(source));
  9. target = Object(value(target));
  10. getOwnPropertyNames(sourceObject).forEach(function (name) {
  11. try {
  12. defineProperty(target, name, getOwnPropertyDescriptor(source, name));
  13. } catch (e) {
  14. error = e;
  15. }
  16. });
  17. if (typeof getOwnPropertySymbols === "function") {
  18. getOwnPropertySymbols(sourceObject).forEach(function (symbol) {
  19. try {
  20. defineProperty(target, symbol, getOwnPropertyDescriptor(source, symbol));
  21. } catch (e) {
  22. error = e;
  23. }
  24. });
  25. }
  26. if (error !== undefined) throw error;
  27. return target;
  28. };