JSFiddle - React, Tailwind, and code Playground

by Abdul Ahmad

JavaScript

function someAsync() {
	return Promise.resolve('async data');
}

class Parent {
	_data = { one: 'val of one' };
  _asyncData;
  
  async doAsync() {
    this._asyncData = await someAsync();
  }
  
  get one() {
  	console.log('parent one getter');
  	return this._data.one;
  }
  
  get oneVal() {
  	return this.one;
  }
  
	get name() {
    console.log('parent name getter');
  	return 'Parent';
  }
}

class Child extends Parent {
	get one() {
  	console.log('child one getter');
    return 'child one';
  }

  get childPrintOne() {
  	this.doAsync().then(r => {
      console.log('one: ', this._asyncData);
    });
  }
  
	get name() {
    console.log('child name getter');
  	return 'Child';
  }
}

let c = new Child();
c.childPrintOne;