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

168
Views
No se pueden "alcanzar" las propiedades de la clase desde el método interno

Estoy tratando de aprender a usar la sintaxis de clase en mi javascript. Esto funciona hasta que se activa el detector de eventos de clic. Cuando llega al método "alternar", la propiedad "_body" ya no parece estar disponible en "esto". Estoy seguro de que se trata de un problema de alcance, pero no puedo ver qué está mal.

Recibo este mensaje de error:

 navigation.js:13 Uncaught TypeError: Cannot read properties of undefined (reading 'classList') at HTMLButtonElement.toggle export default class Navigation { _menuBtn = document.getElementById("primary-nav-menu"); _body = document.getElementsByTagName("body")[0]; constructor() { this._menuBtn.addEventListener("click", this.toggle); } toggle() { this._body.classList.toggle("primary-nav_open"); } }
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!