I have wrote this code in NodeJS. It's a helper that works on a config file that removes some lines and rewrites that file.
Before answer, please see all marked points (with !). Each callback, returns a reference to this, that is the instance of Conf.
Here's how:
Conf.prototype.disableModem = function(modem) {
[...]
return this;
}
Conf.prototype.flush = function(file, cb) {
[...]
cb && cb(err, this);
}
I'm I safe creating it with new and passing the "pointer" through callbacks?
I don't think that the point !4 does something useful, am I right?
Am I doing a memory leak?
Any hint will be appreciated.
MyClass.prototype.disableModem = function(modem, cb) {
this.isIdle = false;
async.waterfall([
function(cb) {
new Conf(settings.sms3.config, cb); // !1
},
function(conf, cb) {
cb(null, conf.disableModem(modem)); // !2
},
function(conf, cb) {
conf.flush(settings.sms3.config, cb); // !3
},
function(conf, cb) {
delete conf; // !4
this.isIdle = true;
cb();
}.bind(this)
], cb);
};