I was having trouble to get around JSHINT complaining about the usage of this
keyword as a possible strict violation
.
Initially I had this simple prototype pattern and I was using function declaration
. In this case JSHINT throws possible strict violation
(function (ns) {
'use strict';
ns.EventData = function (eventData) {
this.id = eventData.id;
this.name = eventData.name;
};
ns.EventData.prototype = (function () {
return {
getDate: getDate
};
// function declaration
function getDate() {
return ns.utils.formatDate(this.date);
};
}());
}(window.myProject));
However when I switched to function expression
everything worked just fine. Can anyone explain why the difference ?
ns.EventData.prototype = (function () {
// function expression
var getDate = function () {
return ns.utils.formatDate(this.date);
};
return {
getDate: getDate
};
}());