I am trying to transform some es5 code to es6 and I stumbled upon the following code and I am wondering if I could replace the util.inherits
with the extends
keyword for classes. I am a bit confused if they do the same thing.
ES5
var EventEmitter = require('events').EventEmitter;
var util = require('util');
function TheEmitter() {
EventEmitter.call(this);
}
util.inherits(TheEmitter, EventEmitter);
ES6
const EventEmitter = require('events').EventEmitter;
class TheEmitter extends EventEmitter {
...
}
via CodeArtist
No comments:
Post a Comment