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

170
Vistas
How to save link on object when I proxy method of object?
const availableTags = ['div', 'h1', 'p', 'span'];

function tagsCollector() {
  this.tags = [];

  this.addTag = function(tag) {
    this.tags.push(tag);
  }
}

class Format {
  constructor() {
    this.tags = new tagsCollector();
  }
}

availableTags.forEach(tag => {
  Object.defineProperty(Format.prototype, tag, {
    value: new Proxy(text => {
      return `
        <${tag}>
          <${this.tags.reduceRight((html, curtag) => {
            return `<${curtag}>${html}</${curtag}>`;
          }, text)}
        </${tag}>
      `
    }, { get: (_, props) => {
      this.tags.addTag(tag);

      return this;
    }})
  })
})

The challenge is field related HTML formatting from codewars. We need to implement the fluent interface pattern of the Format.div.p ('text') type. For each tag, I create a getter that takes the tag of the tag into tagCollector and returns the current Format object. Thought to proxy the getter, but then the call is lost and I cannot access this.tags.

about 4 years ago · Juan Pablo Isaza
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