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

220
Vistas
create promise without constructor nor resolve reject keywords

is it possible to create a promise without using the constructor new promise() nor using =>resolve & =>rejected ? check following method

export function getItById(id) {
  return fetch(`path`, {
    method: 'GET',
  }).then(rslt => {
    if (!rslt || !rslt.ok) {
      throw new Error('failure !');
    } else {
      return rslt.json();
    }
  });
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I'm probably missing something, but it looks like everything is correct. The getItById function returns a promise. There is no need to create a promise.

So when using the function simply do

getItById(2).then(results => {
  console.log(results)
})

To answer the question "is it possible to create a promise without using new promise" the answer is yes, every http call and every database call, or a file read or write returns a 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