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

340
Views
¿Cuáles son los inconvenientes de rendimiento del uso de símbolos globales en métodos getter y setter?

El siguiente código JavaScript tiene un getter y un setter para name usando símbolos globales y age_ usando un guión bajo colgante.

Código JavaScript

 function Human(name, age) { this.name = name; this.age_ = age; } Human.prototype.greet = function() { console.log(`Hello ${this.name}! You are ${this.age} years old.`); }; Human.prototype[Symbol.iterator] = function* () { yield* Object.getOwnPropertyNames(this); yield* Object.getOwnPropertySymbols(this); }; Object.defineProperties( Human.prototype, { name: { get() { return this[Symbol.for('name')]; }, set(value) { this[Symbol.for('name')] = value; }, }, age: { get() { return this.age_; }, set(value) { this.age_ = value; }, }, }, ); let mary = new Human('Mary Smith', 18); mary.greet(); console.dir(mary); let john = new Human('John Doe', 25); john.greet(); console.dir(john);

Salida de consolaSalida de consola del código JavaScript

Quiero saber si hay algún inconveniente de rendimiento en el uso de símbolos globales para métodos getter y setter porque encuentro que es un código mucho más limpio.

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!