inherits.js 862 B

1234567891011121314151617181920212223242526272829
  1. module.exports = inherits
  2. function inherits (c, p, proto) {
  3. proto = proto || {}
  4. var e = {}
  5. ;[c.prototype, proto].forEach(function (s) {
  6. Object.getOwnPropertyNames(s).forEach(function (k) {
  7. e[k] = Object.getOwnPropertyDescriptor(s, k)
  8. })
  9. })
  10. c.prototype = Object.create(p.prototype, e)
  11. c.super = p
  12. }
  13. //function Child () {
  14. // Child.super.call(this)
  15. // console.error([this
  16. // ,this.constructor
  17. // ,this.constructor === Child
  18. // ,this.constructor.super === Parent
  19. // ,Object.getPrototypeOf(this) === Child.prototype
  20. // ,Object.getPrototypeOf(Object.getPrototypeOf(this))
  21. // === Parent.prototype
  22. // ,this instanceof Child
  23. // ,this instanceof Parent])
  24. //}
  25. //function Parent () {}
  26. //inherits(Child, Parent)
  27. //new Child