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

238
Views
¿Cómo accedo a las propiedades en cada instancia de una clase dentro de otra clase?

Necesito acceder a los valores de cada instancia de una clase y compararlos.

Primero, obtengo mis propiedades:

 class One { constructor(){ this.properties = new Properties(); } }

Luego, necesito leer cada instancia que se crea (en cualquier número) y usarlas como argumentos:

 class Two { check(){ if (/* arguments that contain info on all instances of class One */) { // code } } }

Luego necesito crear instancias de la clase Dos y llamar a la función check() .

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

0

Puede usar una propiedad estática en su class One para almacenar las instancias cuando la llama con new, y luego llama a la propiedad estática para obtener una matriz de todas las instancias, eche un vistazo:

 // just to complement the example class Properties { name constructor(name) { this.name = name } } class One { // here is the static property where you will store the instance static allInstances = []; properties constructor(name){ this.properties = new Properties(name); // here you will store the class instance // every time it's created One.allInstances.push(this) } } const instance1 = new One("instance1") const instance2 = new One("instance2") const instance3 = new One("instance3") console.log(One.allInstances) // (3) [_One {...}, _One {...}, _One {...}] class Two { constructor() {} check(instanceNames){ // here I'm logging the name of each instance instanceNames.forEach(instance => console.log(instance.properties.name)) } } const instanceOfTwo = new Two() // pass the array of all instances with One.allInstances instanceOfTwo.check(One.allInstances)

Vea el ejemplo completo , para saber más acerca de los métodos estáticos y sus propiedades, consulte esto .

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!