Создал конструктор на валидацию формы выглядит так
function FormValid(nodeForm){
var _this = this;
this.inputsCollectionNotArray = nodeForm.querySelectorAll('input');
_this.noticeBlockCssSelector = '.notice-block';
this.form = nodeForm;
var counter;
this.inputsArray= [];
for( counter = 0; counter < this.inputsCollectionNotArray.length; counter += 1 ){
this.inputsArray.push(this.inputsCollectionNotArray[counter]);
}
this.submitValidate(this);
}
Есть следующие методы в прототипе, я привожу их пустыми
FormValid.prototype.checkCorrectEmail = function(elemArg){}
FormValid.prototype.emailValidate= function(elemArg){
_this.inputsCollection.forEach( function(element, index, array){
if( element.classList.contains('validate-on-email') ){
_this.checkCorrectEmail(element);
}
});
};
FormValid.prototype.submitValidate = function(){
_this.checkCorrectEmail();
}
window.FormValid = FormValid;
После объявляю объект класса куда передаю узел формы
var formNode = document.getElementById('form-to-validate');
myForm = new window.FormValid(formNode);
Что хочу спросить:
-
я передаю контекст объявляя переменную в каждом методе, подскажите как правильно сделать передачу контекста.
-
как использовать вызов метода
forEach()
. В контексте псевдомассива(коллекции)
в моем решении я создаю новый массив и использую родной методforEach()
this.inputsCollectionNotArray = nodeForm.querySelectorAll(‘input’);
var counter;
this.inputsArray = [];
for( counter = 0; counter < this.inputsCollectionNotArray.length; counter += 1 ){
this.inputsArray.push(this.inputsCollectionNotArray[counter]);
}
Спасибо