I am having troubles with objects properties for a NPM module.
I have this code:
var service = { //In my code this lane is: module.exports = { because is for a npm module so the client will call it using require();
username: 'test',
serviceFunction: function(){
console.log(this.username); //Prints service.username
},
serviceObject: {
getUsername: function () {
console.log(this.username); //THIS IS CAUSING THE FAIL, ITS UNDEFINED
}
}
}
I can access service.username
using this.username
if it is located in a serviceFunction
.
How can I do it while I am in serviceObject.getUsername
?