JSHint警告使用'这个'当我在自调用函数中放入一个函数声明时

时间:2015-12-02 01:17:33

标签: javascript jshint

我有一个"可能的严格违规"来自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 */来抑制它。

谢谢!

0 个答案:

没有答案