Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

87
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda