index.js 888 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict'
  2. var xtend = require('xtend')
  3. var inherits = require('inherits')
  4. module.exports = unherit
  5. // Create a custom constructor which can be modified without affecting the
  6. // original class.
  7. function unherit(Super) {
  8. var result
  9. var key
  10. var value
  11. inherits(Of, Super)
  12. inherits(From, Of)
  13. // Clone values.
  14. result = Of.prototype
  15. for (key in result) {
  16. value = result[key]
  17. if (value && typeof value === 'object') {
  18. result[key] = 'concat' in value ? value.concat() : xtend(value)
  19. }
  20. }
  21. return Of
  22. // Constructor accepting a single argument, which itself is an `arguments`
  23. // object.
  24. function From(parameters) {
  25. return Super.apply(this, parameters)
  26. }
  27. // Constructor accepting variadic arguments.
  28. function Of() {
  29. if (!(this instanceof Of)) {
  30. return new From(arguments)
  31. }
  32. return Super.apply(this, arguments)
  33. }
  34. }