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

185
Views
How to correctly pass property from constructor to method?

When I try to output a property to the console inside a method, I get error error1 is not defined for error1 and console message "undefined" for error2. What am I doing wrong?

class myClass {
  constructor(setting) {
    let error1 = ["fdf", "gff"];
    this.error2 = ["fdf", "gff"];

    for (let i = 0; i < formFields.length; i++) {
        if (formFields[i].tagName === "BUTTON") {
        continue;
    }
      formFields[i].addEventListener("change", this.method.bind(this);
    } 
   }
   isValid(el){
   ...
  }
  method(){
    isValid(this)
    console.log(error1); 
    console.log(this.error2);
  }

Here's a complete example on codsandbox. https://codesandbox.io/s/sleepy-moon-m9kr6?file=/src/index.js

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!