I have a jsnode class c with a constructor and several methods and I create an object by var example = new c(arguments);
One of the methods needs to access the object properties, I do so by using this. The method has function with the following code:
this.Busy=true;
console.log(this); // outputs all the information of the object
Promise.race([Promise.all(
[asynchronousFunction("user1"),asynchronousFunction("user2"),asynchronousFunction("user3")],
TimeoutFunction()])
.then((output)=>{console.log(this);} // this is defined with all information here
And asynchronousFunction looks like this:
var asynchronousFunction= function(userToQuery) {
console.log(this); // undefined
if(this.Busy===false) {
return New Promise((resolve,reject) => {
this.Busy=true;
/* (this code uses promises; it checks the last time an object in the array (this.table) was updated, contacts the server asynchronously, updates the array and returns the result) */
}
}
}
The reason I have to check the array this.table is because the server is overloaded; it should only be queried depending on the timestamp of the data already fetched. How can I make sure the asynchronousFunction can modify the this of the object? I've tried bind, call and arrow functions with no result. I'm becoming desperate.