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

171
Visualizações
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 à 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