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

189
Views
Reference Error: object not defined when trying to initialize a map in a class

Hi im trying to initialize two maps as object in a class:

class Keyboard {

    keys;
    events;

    constructor() {
        keys = {};
        events = {};
    }

}

The variable keys works fine, but on events = {}; this happens:

Uncaught ReferenceError: events is not defined
at new Keyboard (Keyboard.js:8:16)
at app.js:20:14

I can't figure out why would keys works and events not, even if I change their order.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Both shouldn't work, you need to add this, to refer to the object properties.

class Keyboard {

    keys;
    events;

    constructor() {
        this.keys = {};
        this.events = {};
    }

}

const keyboard = new Keyboard()

console.log(keyboard)

about 4 years ago · Santiago Gelvez 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!