Apologies if the terminology is off - javascript isn't my thing.
I have a function:
var input = {
getVal: function () {
return $(this).attr("data-current-val");
},
setVal: function () {
$(this).attr("data-current-val", $(this).val());
},
valHasChanged: function () {
return $(this).val() !== $(this).attr("data-current-val");
}
};
As you can see there is some repetition. Firstly, I repeat the data attribute
name several times; secondly, I select a jquery object
numerous times.
I've tried to remove the repetition. For instance, in respect of the data attribute, by adding node: "data-current-val"
at the top and then calling it with this.node
in place of the string. That causes an error, as does trying to define and then use the jquery object
in the same way.
Similarly part of the boolean in valHasChanged $(this).attr("data-current-val")
, logically could be replaced by this.getVal
but that doesn't seem to work either. Where am I going wrong?!
Any help appreciated.