Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

86
Vistas
Reference to Promise.all

This code works:

Promise.all([Promise.resolve(1)])

However, this code does not:

const f = Promise.all

f([Promise.resolve(1)])

The second piece of code throws the following error: Uncaught TypeError: Promise.all called on non-object.

Why can't I assign the function Promise.all to a variable and use it as normal?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Because that's what the spec requires.

1. Let C be the this value.
2. Let promiseCapability be ? NewPromiseCapability(C).
3. Let promiseResolve be Completion(GetPromiseResolve(C)).
...

The all function requires its this value to be a constructor function that supports the parameter conventions of the Promise constructor.

Your current code is not calling the function as part of an object (that is, f is a standalone identifier), so the resulting this is either the global object or undefined, depending on whether you're in strict mode or not - either way, the above requirement is not fulfilled.

If you bind the function to Promise, it'll work.

const f = Promise.all.bind(Promise);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda