function jQueryValidatorWrapper(formId, rules, messages) {
var validator = $("form:visible[id='" + formId + "']").validate({
onchange: false,
messages: messages,
rules: rules
});
this.validate = function (hideErrors) {
var showErrorMessage = hideErrors ? false : true;
// What does 'validator' refer to?
var result = validator.form();
};
}
When I execute this,
var validatorObj = new jQueryValidatorWrapper('testForm', [], []);
validatorObj.validate();
The jQueryValidatorWrapper function had only one method declared with this, so when the constructor executed, it simply created an object with the validate method.
What happens to validator variable declared inside jQueryValidatorWrapper? It is not prefixed with this so it is not part of the object being constructed.
Is the validator variable a global? or is it part of the closure which is the validate method?
validatoris not a global variable... it will exists in the closure though