this : nested functions - bind
JavaScript
class Service {
constructor(){
this.numbers = [1,2,3];
this.token = "token";
}
doSomething(){
setTimeout(function doAnotherThing(){
this.numbers.forEach(function log(number){
console.log(number);
console.log(this.token);
}.bind(this));
}.bind(this), 100);
}
}
let service = new Service();
service.doSomething();