So when i call the code below the outputted value of name is always "testname" the default value. It should be 'newvalue;
// Constructor
function test(connection) {
this.name = 'testname';
}
test.prototype.exec = function () {
var Request = require('tedious').Request // this could be any event emitter;
request = new Request("select id, name from somevals where id = 1", function (err, rowCount) {
if (err) {
console.log(err);
} else {
console.log(rowCount + ' rows');
}
});
this.connection.execSql(request);
request.on('row', function (columns) {
this.name = 'newvalue'; //how do i set the instance variable name so that it is visible to the calling module
});
};
// export the class
module.exports = test;
Calling looks like
var test = require("./Model/test");
var b = new test(connection);
b.exec();
console.log(b.name);