Search
 
SCRIPT & CODE EXAMPLE
 

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)
  }
}
Comment

initializing a property asynchronously 2

const dc = new DataContainer();
assert.equal(dc.getData(), 'DATA: undefined');
setTimeout(() => assert.equal(
  dc.getData(), 'DATA: downloaded'), 0);
Comment

PREVIOUS NEXT
Code Example
Javascript :: objection eager loading 
Javascript :: unban command discord.js v12 
Javascript :: angular form initialse 
Javascript :: javascript firebase kicks out current user 
Javascript :: ERROR in ./node_modules/pretty-format/node_modules/ansi-regex/index.js Module build failed: Error: ENOENT: no such file or directory 
Javascript :: vscode new file crlf 
Javascript :: js remove undefined object 
Javascript :: radio button not checked when clicked react 
Javascript :: filter a characters from words in javascript array 
Javascript :: use ES6 import syntax when you enhance the script tag 
Javascript :: release mouse key javascript 
Javascript :: remove json parameter 
Javascript :: table antd dosen t update 
Javascript :: react pass object to state 
Javascript :: "Perform native operation by javascript in Android" 
Javascript :: login_page-jwt-auth-using-react-and-flask 
Javascript :: how to express all characters in keyboard in js reg exp 
Javascript :: js hit asp button onclick event 
Javascript :: accessing state in nuxt vuex 
Javascript :: setFocus() in searchbar ionic4 
Javascript :: rechart graph 
Javascript :: react spring bounce in animation 
Javascript :: random color javascript 
Javascript :: video link on videojs 
Javascript :: jquery check screen width 
Javascript :: javascript Detect Cycle in a Directed Graph 
Javascript :: move an object in array by latest clicked 
Javascript :: hoe to find items in mongoose 
Javascript :: payflex api examples php 
Javascript :: how can i debug compressed javascript in chrome 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =