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