-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
Closed
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.utilIssues and PRs related to the built-in util module.Issues and PRs related to the built-in util module.
Description
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?
Metadata
Metadata
Assignees
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.utilIssues and PRs related to the built-in util module.Issues and PRs related to the built-in util module.