Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

initializing a property asynchronously

class DataContainer {
  #data; // (A)
  constructor() {
    Promise.resolve('downloaded')
      .then(data => this.#data = data); // (B)
  }
  getData() {
    return 'DATA: '+this.#data; // (C)
  }
}
Source by exploringjs.com #
 
PREVIOUS NEXT
Tagged: #initializing #property #asynchronously
ADD COMMENT
Topic
Name
7+1 =