0

I'm developing a little app in nodejs 8. I have a class that already extends another class

module.exports = class ClassOne extends ClassTwo {

}

But I'd also like my class to have the functionality of the EventEmitter class which I believe would also require me extending to do so. I've seen that multiple inheritance is possible but I've found most documentation unclear on what's the least messy way to accomplish this for Node 8. It feels like this should be a common use case as the EventEmitter is quite widely used.

Is there a best practise for doing this in node 8?

Peter Fox
  • 1,809
  • 2
  • 20
  • 34
  • I would suggest composition over inheritance and have an EventEmitter property of `ClassOne`. – Explosion Pills May 22 '18 at 18:43
  • @ExplosionPills I guess that makes sense, I assume it's it's a constant then it can't be rewritten or anything stupid like that right? – Peter Fox May 22 '18 at 18:46
  • I'm not sure I understand. What's a constant? You want to avoid rewriting? – Explosion Pills May 22 '18 at 18:47
  • @ExplosionPills I mean, this is going to be a public property – Peter Fox May 22 '18 at 18:48
  • JavaScript doesn't really have private properties as such -- when you `extends` all of the properties are accessible on the object anyway so even if you did extend `EventEmitter` all of the `EventEmitter` properties would be accessible. – Explosion Pills May 22 '18 at 18:50

0 Answers0