My code contains the function calls as follows
module.exports = {
func1() {
// var parentThisScope = this;
this.func2(param, function(err, data) {
this.func4(data, function(err, result) {
return result; // problem
});
});
},
func2() {
// some IO
},
func3() {
// some IO
},
func4() {
this.func3(params, function(err, data){
// some IO // problem
});
}
}
But, when I try to access the functions func4() from inside of func2() and func3() from inside of func4(), it throws error this.func4() and this.func3() is not a function. I tried adding a var to store the root scope(as shown in the code I stored this in the variable parentThisScope). It seems like when I call a property the scope of this changes as well. If that is the case, can anyone explain what exactly is happening and how to deal with it in a better way instead of just storing the rootscope.