尝试继承 EvenEmitter 时出现错误
/* Consumer.js */
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var Consumer = function() {};
Consumer.prototype = {
// ... functions ...
findById: function(id) {
this.emit('done', this);
}
};
util.inherits(Consumer, EventEmitter);
module.exports = Consumer;
/* index.js */
var consumer = new Consumer();
consumer.on('done', function(result) {
console.log(result);
}).findById("50ac3d1281abba5454000001");
/* ERROR CODE */
{"code":"InternalError","message":"Object [object Object] has no method 'findById'"}
我已经尝试了几乎所有方法,但仍然无法正常工作