I have a validator library, that is sanitizing and validate strings. The validator functions are pushing a message to a array "errors" for every nonvalid input they find.
When validation on all input is complete I collect the errors in a variable like this:
var errors = validator.getErrors();
// Function definition
Validator.prototype.getErrors = function () {
return this._errors;
}
The var "errors" will now be an array containing 0 to several string elements. Right after this I'm calling a function for emptying the errors in the validator.
validator.clearErrors();
// Function definition
Validator.prototype.clearErrors = function () {
this._errors = [];
}
Question: Can i somehow re write the getErrors() function so that is also empty it's internal _errors variable?... Then I can remove the clearErrors function altogether.