7

Trying to validate some Javascript in JsHint, and I get the following:

Possible strict violation:

return ($.event.dispatch || $.event.handle).apply(this, args);

Any ideas why it's throwing that error?

Thanks guys

user1945912
  • 597
  • 3
  • 9
  • 19

1 Answers1

14

JSHint isn't sure whether the function that code is in will be called with an actual this.

To tell JSHint how the function will be called and suppress this warning, add /*jshint validthis: true */ to the top of the function.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • Perfect, didn't know you could do that, thanks! – user1945912 May 14 '13 at 21:40
  • awesome. doesn't have to be at the top of the function apparently, in my unit test I had to test the context the function was being called in, I added the jshint comment just above where I used `this` (for contextual reference) and it still worked for me. – Shanimal May 10 '16 at 22:53
  • wondering if you should necromance this answer in the question this is marked a duplicate of? (because I didn't see it there) – Shanimal May 10 '16 at 22:56