mixin.js 913 B

1234567891011121314151617181920212223242526
  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) { error = e; }
  14. });
  15. if (typeof getOwnPropertySymbols === "function") {
  16. getOwnPropertySymbols(sourceObject).forEach(function (symbol) {
  17. try {
  18. defineProperty(target, symbol, getOwnPropertyDescriptor(source, symbol));
  19. } catch (e) { error = e; }
  20. });
  21. }
  22. if (error !== undefined) throw error;
  23. return target;
  24. };