我有一个"可能的严格违规"来自JSHint的关于使用this
关键字的警告。 this问题的OP遇到了类似的问题(在更新中提到),但我不认为有人解决了它的原因。我的代码格式为:
foo.prototype = (function (){
"use strict";
function bar (barfoo) {
if(this.foobar === 0)
{
//do something
}
}
})();
在这种情况下,JSHint抱怨使用this
关键字("可能的严格违规")。但是,如果我将其更改为:
foo.prototype = (function (){
"use strict";
var bar = function (barfoo) {
if(this.foobar === 0)
{
//do something
}
}
})();
这背后的原因是什么?我想了解原因,而不是仅使用函数表达式或/* jshint validthis: true */
来抑制它。
谢谢!