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

135
Views
¿Cómo inicializar una variable de clase como una matriz vacía en JavaScript?

Básicamente, solo quiero asignar el valor predeterminado de una variable de clase a una matriz vacía.

Intenté lo siguiente, pero no tuve suerte:

 class Test { constructor(myArray = []) { this.myArray = myArray; } }

Obviamente, esto no funciona, ya que cuando intento imprimir Test.myArray, se devuelve undefined en lugar de una matriz vacía.

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

0

Está intentando acceder a Prototype, su clase se inicializó correctamente, solo haga lo siguiente:

 class Test { constructor(myArray = []) { this.myArray = myArray; } } const t = new Test(); console.log(t.myArray)

new palabra clave significa que está creando una nueva instancia de la clase Test.

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!