Why is this needed in javascript function inside an object? -
i have piece of javascript code:
$scope.rectifyform = { visible: false, rateerrormessage: "", rectifyerrormessage: "", isvalid: function () { return this.rateerrormessage.length === 0 && this.rectifyerrormessage.length === 0; } };
in isvalid
method want check of both variables set. piece of code works because i've used this
keyword. however, if omit this
, error these variables undefined.
could explain why is? why need use this
?
rateerrormessage
not variable in scope of function being called; property of object (so have specify theobject.rateerrormessage
). since object context in function called, available via this
.
Comments
Post a Comment