javascript - How to properly address this JSHint "Possible strict violation" -
edit: issue related jshint, rather jslint - changed tag.
the following gives me "possible strict violation". understand why violation occurs - because of use of this
in function jslint doesn't believe method:
function widget(name){ this.name = name; } widget.prototype.dosomething = dosomething; function dosomething(){ console.log(this.name + " did something"); }
although, following approaches solve jslint warning, force me code organization rather avoid:
1) declaring function inline:
widget.prototype.dosomething = function (){ console.log(this.name + " did something"); }
2) creating wrapper function passes this
:
widget.prototype.dosomething = function (){ return dosomething(this); }; function dosomething(self){ // ... }
is there way organize code solve issue other using approaches above?
the way properly address in question. #1:
widget.prototype.dosomething = function (){ console.log(this.name + " did something"); }
the whole point of linting prevents making common mistakes in source code, , error you're seeing correct: shouldn't ever see this
mentioned in function not declared on object.
linting has nothing way program behaves when executed. it's not linting doesn't "believe" method invoked on object, it's source code contains pattern known problematic. can work around like, long pattern still in source, still have linting problem.
if want ignore it, wrap in /*ignore jslint start*/
, /*ignore jslint end*/
, problem still there.
Comments
Post a Comment