I am switching from Java to NodeJs so some things are still blurry to me.
I am trying to work with scripts as I would do with classes in Java. I've learned this is the way to do it:
var client = require('scp2');
var host, username, password;
var SftpHandler = function (host, username, password) {
this.host = host;
this.username = username;
this.password = password;
};
SftpHandler.prototype.downloadFile = function (path, callback) {
console.log(this.host,username,password,path);
};
module.exports = SftpHandler;
The problem is when I call it from another script like this:
var sftpHandler = new SftpHandler(credentials.sftpHost, credentials.sftpUsername, credentials.sftpPassword);
sftpHandler.downloadFile(credentials.sftpPathToImportFiles+configFile.importFileName, callback);
I am having 162.*.*.* undefined undefined undefined ...
in the console log.
I've realized it is due to I am lacking this.
in the object attributes I am referring to. But why is this.
needed? Is that the right way to do it?