저는 nodejs 모듈을 작성 중이며 이벤트 이미 터를 "scrappy.get"에 바인드하려고합니다. "scrappy"....에 바인딩 할 수있는 것 같습니다. "scrappy.get (key) .on ('complete'...."는 작동하지 않습니다.)자식 객체에 이벤트를 내 보냅니다.
자식 객체의 수 '
내 NodeJS 모듈 :
var util = require('util'),
EventEmitter = require('events').EventEmitter;
function Scrappy(id) {
}
util.inherits(Scrappy, EventEmitter);
Scrappy.prototype.get = function (key) {
var self = this;
self.emit('complete', "here");
**return this;**
}
module.exports = Scrappy;
내 NodeJS 응용 프로그램 코드 :
var Scrappy = require('./scrappy.js')
var scrappy = new Scrappy("1234");
scrappy.get("name").on('complete', function(data){
console.log("secondary");
});
결과 :
scrappy.get("name").on('complete', function(data){
^
TypeError: Cannot call method 'on' of undefined
편집 : 해결. "return this;"추가 그것을 위해 해결되었습니다. 고맙습니다!
흠, 작동하지 않는 것 같습니다. nodejs 응용 프로그램에서 여전히 얻고 있습니다 : scrappy.get ("name") on ('완료', 함수 (데이터) { ^ TypeError : 정의되지 않은 'on'속성을 읽을 수 없습니다. – klinquist
주요 문제 당신이'get()'에서'.on() '을 호출 할 수 있도록 Scrappy 인스턴스를 반환하지 않는다는 것입니다. – mscdex
mscdex, 도와 주셔서 감사합니다. 그러나 저에게 도움이되지 않습니다 .. – klinquist