var stream = require('stream');
var util = require('util');
util.inherits(Answers, stream.Readable);
function Answers(opt) {
stream.Readable.call(this, opt);
this.quotes = ["yes", "negatory", "possibly"];
this._index = 0;
}
Answers.prototype._read() = function() {
if (this._index > this.quotes.length) {
this.push(null);
}
else {
this.push(this.quotes[this._index]);
this._index += 1;
}
};
我的错误表明我的左侧分配无效,我试图覆盖stream.Readable的原型(第12行)。我以为是打电话给
util.inherits(Answers, stream.Readable);
允许我重写stream.Readable的_read()函数。任何帮助将非常感谢。提前谢谢!
答案 0 :(得分:3)
Answers.prototype._read()
...您正在为函数调用分配值。只需将其更改为Answers.prototype._read = function() ...
。