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

166
Views
Cannot "reach" class properties from inside method

I am trying to learn to use class syntax in my javascript. This is working until the click eventlistener is activated. When it reaches the "toggle" method the "_body" property doesn't seem to available anymore on "this". I am sure this is a scope problem but i cannot see whats wrong.

I get this error message:

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!