JSFiddle - React, Tailwind, and code Playground

by Tiago Sousa

JavaScript

class Teste {
	constructor() {
  	this.value = 0;
    console.log(this.value);
  }
  
  step1() {
  	return new Promise((resolve, reject) => {
      setTimeout(() => {
	   		this.value = 1;
	    	console.log(this.value);
	      resolve();     
      }, 2)
    });
  }
  
  step2() {
  	return new Promise((resolve, reject) => {
  		this.value = 2;
    	console.log(this.value);
      resolve();
    });
  }
  
  run() {
  	this.step1()
    .then(() => this.step2())
    .then(() => console.log(this.value));
  }
}

c = new Teste();
c.run();