I am dealing with the following situation.
I have to use a method from the class, but I have to call a callback too...
Look at the code, I have created the _this var because I don't know how to access the DeviceAnalyzer instance from inside the anonymous function...
Is there another way? I think the way I did it is kind of nasty haha
DeviceAnalyzer.prototype.pingProcess = function(deviceInfo, callback) {
var _this = this;
netutils.ping(host.ipAddress, function(isAlive) {
deviceInfo.isAlive = isAlive
_this.emit('device', deviceInfo);
callback(null, deviceInfo);
});
};
this. This code is legible and yields the result same as other solutions.apply,callorbindjust pick one.