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

101
Vistas
Refactoring a Bug Reporting Function into a Helper Class

I've been reading documentation about Javascript Classes all day, and now I want to refactor a Bug Report function into it's own class, but even when I begin to write my class as below:

class bugReport {
  constructor(x, y)
   this.x = x;
   this.y = y;
}

I struggle to think how to even begun breaking down the constituent pieces of my Bug Report into the format of a Javascript Class ie. what is x, y when it's comes to a Reporting Feature? s there a way to look at the steps of a class creation that makes it easier, or a pattern you follow? I'll attach my original bugreport code below to give you an example of what I'm attempting to make a class of.

BugReport:

     $("#bug").submit((e) => {
                e.preventDefault()
                const input = document.getElementById('nameInput');
                bugInfo = {
                  "name": `[${ticket.id}] Bug report`,
                  "story_type" : "Bug",
                  "description": `+ ${urlHelper}` + " \n" + `+ ${input.value}`,
                }
                reportBug(bugInfo).then(collapse.collapse('toggle'))
              })
            });

 async function reportBug(data = {}) {
      const url = 'exampleUrl'
      const response = await fetch(url, {
        method: 'POST',
        headers: {
          "Token": `${metadata.settings.token}`,
          "Content-Type": "application/json"
        },
        body: JSON.stringify(data)
      });
      return response.json();
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I am not really a JavaScript expert, but I would do it like this:

class Logger {
    static async logInfo(data = {}) {
      const url = 'exampleUrl'
      const response = fetch(url, {
        method: 'POST',
        headers: {
          "Token": `${metadata.settings.token}`,
          "Content-Type": "application/json"
        },
        body: JSON.stringify(data)
      });
      return response.json();
    }
}

Also, since you asked about a pattern you follow, I would suggest you read upon Cross-cutting concern. Here are a few links:

  1. https://en.wikipedia.org/wiki/Cross-cutting_concern
  2. https://www.c-sharpcorner.com/UploadFile/vendettamit/managing-cross-cutting-concerns-the-logger-and-logging/
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