Javascript – JSLint Error: Unexpected ‘this’


Having trouble understanding why JSLint is surprised by my use of this in the following code:

function testConstr (x) {
    'use strict';
    this.joker = "Whyyy sooo seriousss?";
    this.x = x;

For both property assignments, JSLint says: Unexpected 'this'. How do I correct my code?

Best Solution

Your code might be perfectly correct (it might also be problematic, depending on how you call testConstr).

My suggestion is: tell JSLint to shut up

enter image description here

Or don't use JSLint at all.