I have functions
const change = (nameInput, nameError, nameRegexp) => {
return () => {
const val = nameInput.value;
if (!regexp.nameRegexp.test(val)) {
error.classList.add('animation');
error.innerHTML = errorMessage.nameError;
nameInput.classList.remove('correct');
} else {
nameInput.classList.add('correct');
error.classList.remove('animation');
}
}
}
lastName.addEventListener('change', change(lastName, name, name));
The problem is that the nameError
, nameRegexp
properties are not visible in the middle of the function.
Why is this happening? How to fix this error?