Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*!
  2. * merge-descriptors
  3. * Copyright(c) 2014 Jonathan Ong
  4. * Copyright(c) 2015 Douglas Christopher Wilson
  5. * MIT Licensed
  6. */
  7. 'use strict'
  8. /**
  9. * Module exports.
  10. * @public
  11. */
  12. module.exports = merge
  13. /**
  14. * Module variables.
  15. * @private
  16. */
  17. var hasOwnProperty = Object.prototype.hasOwnProperty
  18. /**
  19. * Merge the property descriptors of `src` into `dest`
  20. *
  21. * @param {object} dest Object to add descriptors to
  22. * @param {object} src Object to clone descriptors from
  23. * @param {boolean} [redefine=true] Redefine `dest` properties with `src` properties
  24. * @returns {object} Reference to dest
  25. * @public
  26. */
  27. function merge(dest, src, redefine) {
  28. if (!dest) {
  29. throw new TypeError('argument dest is required')
  30. }
  31. if (!src) {
  32. throw new TypeError('argument src is required')
  33. }
  34. if (redefine === undefined) {
  35. // Default to true
  36. redefine = true
  37. }
  38. Object.getOwnPropertyNames(src).forEach(function forEachOwnPropertyName(name) {
  39. if (!redefine && hasOwnProperty.call(dest, name)) {
  40. // Skip desriptor
  41. return
  42. }
  43. // Copy descriptor
  44. var descriptor = Object.getOwnPropertyDescriptor(src, name)
  45. Object.defineProperty(dest, name, descriptor)
  46. })
  47. return dest
  48. }