EDIT: this issue is related to JSHint, rather than JSLint - changed the tag.
The following gives me a "possible strict violation". I understand why the violation occurs - this is because of the use of this
in a function that jslint doesn't believe is a method:
function Widget(name){
this.name = name;
}
Widget.prototype.doSomething = doSomething;
function doSomething(){
console.log(this.name + " did something");
}
Although, the following approaches solve the jslint warning, they force me into a code organization that I would rather avoid:
1) declaring the function inline:
Widget.prototype.doSomething = function (){
console.log(this.name + " did something");
}
2) creating a wrapper function that passes this
:
Widget.prototype.doSomething = function (){ return doSomething(this); };
function doSomething(self){
// ...
}
Is there a way to organize the code to solve the issue other than using the approaches above?