JSLint 意外 'this' 错误

JSLint Unexpected 'this' Error

为什么我从下面的代码中得到以下 JSLint 错误:

JSLint : Unexpected 'this'.

var environment = {
    development: "Development",
    staging: "Staging",
    production: "Production",
    current: function () {
        return process.env.ASPNET_ENV || this.development;
    },
    isDevelopment: function () {
        return this.current() === this.development;
    },
    isStaging: function () {
        return this.current() === this.staging;
    },
    isProduction: function () {
        return this.current() === this.production;
    }
};

我已经看过一些类似的问题,例如 this,但是 none 处理上面的代码,其中 'this' 以不同的方式使用。

这很奇怪,但 JSLint 似乎默认不允许 'this'。

但是,他们的文档中有一个 'Tolerate this' 选项。所以我想在您的 jslint 配置中添加一个选项,如下所示:

/*jslint this:true */