Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

83
Views
clase mecanografiada con constructor llamando a una función asíncrona interna que inicia una propiedad

Actualización: no estoy pidiendo este constructor de clase Async/Await porque, como dije, quiero mantener el asíncrono DENTRO del constructor.

Puedo crear una instancia de esta clase sin problemas, excepto que no puedo obtener su propiedad de texto justo después de la creación. ¿Existe una manera simple sin cambiar demasiado la estructura actual (mantener la función asíncrona dentro del constructor y llamarla desde el constructor)?

 class Test { _text: string; get text() { return this._text; } constructor() { (async () => { this._text = await _init(); console.log(this._text); return this; })(); async function _init() { return "hello"; } } } let test = new Test(); let text = test.text; console.log(text);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!