javascript - 'this.variable' doesn't change? -
I will create a group of new objects from the function below, then from within a loop, I loop through each one and Call methods toggleValid () and toggleErrMsg () in ToggleErrMsg (), it assumes that the value of object.errMsgStatus is correct, but it is not. Why?
InputField (field, cssTarget, value, error message, verifier) function {var self = this; This.field = Area, this.cssTarget = cssTarget, this.value = value, this.valid = false, this.errMsg = errMsg, this.errMsgStatus = false, this.validator = validator, this.toggleErrMsg = function () { If (self.valid === false & self-Erstestus === false) {self.errMsgStatus = true; RenderValidationError (auto, incorrect); } And {self.errMsgStatus = false; RenderValidationError (auto, true); }} This.toggleValid = function () {self.validator (); If (! Self.valid) {self.cssTarget () AddClass ("inputInvalid"); } Else {self.cssTarget (). RemoveClass ("inputInvalid"); }}}}
Perhaps you have to do with the way to start the input field. As no code has been given, you are probably
var inputField = InputField ();
While this should be
var inputField = new InputField ();
Comments
Post a Comment