1
0

mixin.js 877 B

123456789101112131415161718192021222324252627
  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. };