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

249
Views
¿Es posible Proxy primitivas (cadenas, números)?

Estoy explorando Proxies en JavaScript, y quiero saber si hay alguna forma de primitivas Proxy . Si trato de hacerlo:

 new Proxy('I am a string');

Arroja Uncaught TypeError: `target` argument of Proxy must be an object, got the string "I am a string"


La razón por la que quiero hacer esto es poder representar los métodos prototipo de la primitiva. Podría editar el prototipo, pero editar cada función de prototipo de cada primitivo no parece viable.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede solucionarlo envolviendo el valor primitivo en un objeto:

 const proxy = new Proxy({ value: 'I am a string' }, { get(target, prop, receiver) { const prim = Reflect.get(target, 'value'); const value = prim[prop]; return typeof value === 'function' ? value.bind(prim) : value; } }); proxy.endsWith('ing'); // => true proxy.valueOf(); // => 'I am a string' 'test ' + proxy; // => 'test I am a string' proxy[0]; // => 'I'
about 4 years ago · Juan Pablo Isaza Report
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!