Ну, нам не хватает некоторого кода, но я почти уверен, что this
в обратном вызове listen
не будет вашим myServer
объектом.
Вы должны кешировать ссылку на неговне обратного вызова и используйте эту ссылку ...
function myServer(map, port, server) {
this.start = function () {
console.log("here");
var my_serv = this; // reference your myServer object
this.server.listen(port, function () {
console.log(counterLock);
console.log("here-2");
my_serv.emit('start'); // and use it here
my_serv.isStarted = true;
});
}
this.on('start',function(){
console.log("wtf");
});
}
... или bind
внешнее значение this
для обратного вызова ...
function myServer(map, port, server) {
this.start = function () {
console.log("here");
this.server.listen(port, function () {
console.log(counterLock);
console.log("here-2");
this.emit('start');
this.isStarted = true;
}.bind( this )); // bind your myServer object to "this" in the callback
};
this.on('start',function(){
console.log("wtf");
});
}