Vote count:
0
I am wondering why, when creating a new stream class in node, I need to use both call and util.inherits
For instance, in the following code, which is used to create a readable stream, I have to use both:
var Readable = require('stream').Readable;
var util = require('util');
var MyStream = function (options) {
Readable.call(this, options)
}
util.inherits(MyStream, Readable); //Hasn't this already inherited all methods from Readable via "call"
var stream = new MyStream();
It seems to be that Readable.call is calling the constructor from Readable and therefore the util.inherits is unnecessary.
asked 2 mins ago
1 Answer
Vote count:
0
util.inherits will merge the prototype chain from Readable into MyStream. Both are required for a more complete sense of inheritance.
answered 4 secs ago
Why use util.inherits and .call for inheritance in Node.js
Aucun commentaire:
Enregistrer un commentaire