I'm experimenting with ES6 classes and noticed I was unable to use util.inherits to inherit EventEmitter into the prototype of my class.
'use strict';
var util = require('util');
var EventEmitter = require('events').EventEmitter;
class x {
constructor() {
EventEmitter.call(this);
}
emitEvent() {
this.emit('event emitted!');
}
}
util.inherits(x, EventEmitter); // Fails
The error is TypeError: Cannot assign to read only property 'prototype' of class x { constructor() { EventEmitter.call(this); } emitEvent() { this.emit('event emitted!'); } }
I was able to get inheritance to work using class x extends EventEmitter, but using extends means my class can't be a subclass of anything besides EventEmitter unless I make EventEmitter the root class.
Thoughts on this?