Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!