0

Why am I getting the following JSLint error from the code below:

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;
    }
};

I have already seen a few similar questions like this one but none deal with the code above, where 'this' is used in a different manner.

Muhammad Rehan Saeed
  • 35,627
  • 39
  • 202
  • 311
  • 2
    Maybe you could find an answer here: http://stackoverflow.com/questions/30314944/jslint-error-unexpected-this – Roman Alesenkov Nov 26 '15 at 20:56
  • 1
    I suggest to use eslint instead, which is a lot more configurable: http://eslint.org/ . I guess Crockford doesn't want you to use `this` at all. – Felix Kling Nov 26 '15 at 20:56
  • Yep, this is a dupe. Check [the question in mentioned by @RomanAlesenkov](http://stackoverflow.com/questions/30314944/jslint-error-unexpected-this). This (no pun intended, ha ha) rule is new for the ES6 version of JSLint, and has an option to turn the rule off throughout your file. – ruffin Nov 27 '15 at 02:04

1 Answers1

4

This is very strange, but seems like JSLint doesn't allow 'this' by default.

However, there's a 'Tolerate this' option available in their docs. So I'd suppose adding an option to your jslint config, like this:

/*jslint this:true */
Eugene Sue
  • 1,320
  • 1
  • 9
  • 13