this : nested functions - that

by Cristi Salcescu

JavaScript

class Service {
	constructor(){
  	this.numbers = [1,2,3];
    this.token = "token";
  }
  
  doSomething(){
  	let that = this;
  	setTimeout(function doAnotherThing(){
    	that.numbers.forEach(function log(number){
      		console.log(number);
          console.log(that.token);
      });
    }, 100);
  }	
}

let service = new Service();
service.doSomething();