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

125
Views
Cómo agregar datos privados a un objeto arbitrario sin usar un WeakMap

Está bien. Esta no es realmente una pregunta, sino una epifanía que tuve hoy y que me gustaría compartir, porque no sé si alguien se da cuenta.

Considere el siguiente código:

 function Id(obj) { return obj; } class Meta extends Id { #data; constructor(obj, data) { super(obj); this.#data = data; } getData() { try { return this.#data; } catch (ex) {} } setData(value) { try { this.#data = value; } catch (ex) { new Meta(this, value); } } static get = Function.call.bind(this.prototype.getData); static set = Function.call.bind(this.prototype.setData); } var obj = Object.freeze({}); // !!!! frozen console.log(Meta.get(obj)); // undefined Meta.set(obj, "test"); console.log(Meta.get(obj)); // "test" console.log(Reflect.ownKeys(obj)); // Array []

Como puede ver, agregué una variable privada a un objeto congelado externo al que solo se puede acceder con mi código.

Gracias por leer y disfrutar!!!!

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!