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

197
Views
¿Cómo exactamente la palabra clave 'esta' asigna propiedades a las funciones en javascript?

Traté de recrear la promesa de javascript, siguiendo este tutorial , este es el código completo del tutorial:

 function myPromise(callback) { let resolve = function(value){ this.resolveCallback(value); } callback(resolve) } // .then myPromise.prototype.then = function(resolveCallback){ attachResolveCallback(resolveCallback); } const attachResolveCallback = function(resolveCallback){ this.resolveCallback = resolveCallback; }

estoy confundido acerca de la parte que implementa .then():

 // .then myPromise.prototype.then = function(resolveCallback){ attachResolveCallback(resolveCallback); } const attachResolveCallback = function(resolveCallback){ this.resolveCallback = resolveCallback; }

¿Por qué se necesita const attachResolveCallback, en lugar de solo usar esta palabra clave en la función prototipo?

Así que reemplacé la parte .then del código con:

 myPromise.prototype.then = function(resolveCallback){ this.resolveCallback = resolveCallback; }

Pero el código no funciona y devuelve un error:

 promise.js:4 Uncaught TypeError: this.resolveCallback is not a function at resolve (promise.js:4:14) at promise.js:25:9

Sospecho que este problema se debe al uso de 'esto' al asignar propiedades a las funciones, pero no estoy seguro del motivo específico aquí. ¿Alguien podría iluminarme sobre este problema?

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!